UNPKG

4.85 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3/**
4 * @license
5 * Copyright Google Inc. All Rights Reserved.
6 *
7 * Use of this source code is governed by an MIT-style license that can be
8 * found in the LICENSE file at https://angular.io/license
9 */
10const architect_1 = require("@angular-devkit/architect");
11const node_1 = require("@angular-devkit/architect/node");
12const testing_1 = require("@angular-devkit/architect/testing");
13const core_1 = require("@angular-devkit/core");
14exports.ivyEnabled = process.argv.includes('--ivy');
15const devkitRoot = core_1.normalize(global._DevKitRoot); // tslint:disable-line:no-any
16exports.workspaceRoot = core_1.join(devkitRoot, `tests/angular_devkit/build_angular/hello-world-app${exports.ivyEnabled ? '-ivy' : ''}/`);
17exports.host = new testing_1.TestProjectHost(exports.workspaceRoot);
18exports.outputPath = core_1.normalize('dist');
19exports.browserTargetSpec = { project: 'app', target: 'build' };
20exports.devServerTargetSpec = { project: 'app', target: 'serve' };
21exports.extractI18nTargetSpec = { project: 'app', target: 'extract-i18n' };
22exports.karmaTargetSpec = { project: 'app', target: 'test' };
23exports.tslintTargetSpec = { project: 'app', target: 'lint' };
24exports.protractorTargetSpec = { project: 'app-e2e', target: 'e2e' };
25async function createArchitect(workspaceRoot) {
26 const registry = new core_1.schema.CoreSchemaRegistry();
27 registry.addPostTransform(core_1.schema.transforms.addUndefinedDefaults);
28 const workspaceSysPath = core_1.getSystemPath(workspaceRoot);
29 const workspace = await core_1.experimental.workspace.Workspace.fromPath(exports.host, exports.host.root(), registry);
30 const architectHost = new testing_1.TestingArchitectHost(workspaceSysPath, workspaceSysPath, new node_1.WorkspaceNodeModulesArchitectHost(workspace, workspaceSysPath));
31 const architect = new architect_1.Architect(architectHost, registry);
32 return {
33 workspace,
34 architectHost,
35 architect,
36 };
37}
38exports.createArchitect = createArchitect;
39async function browserBuild(architect, host, target, overrides, scheduleOptions) {
40 const run = await architect.scheduleTarget(target, overrides, scheduleOptions);
41 const output = (await run.result);
42 expect(output.success).toBe(true);
43 expect(output.outputPath).not.toBeUndefined();
44 const outputPath = core_1.normalize(output.outputPath);
45 const fileNames = await host.list(outputPath).toPromise();
46 const files = fileNames.reduce((acc, path) => {
47 let cache = null;
48 Object.defineProperty(acc, path, {
49 enumerable: true,
50 get() {
51 if (cache) {
52 return cache;
53 }
54 if (!fileNames.includes(path)) {
55 return Promise.reject('No file named ' + path);
56 }
57 cache = host
58 .read(core_1.join(outputPath, path))
59 .toPromise()
60 .then(content => core_1.virtualFs.fileBufferToString(content));
61 return cache;
62 },
63 });
64 return acc;
65 }, {});
66 await run.stop();
67 return {
68 output,
69 files,
70 };
71}
72exports.browserBuild = browserBuild;
73exports.lazyModuleFiles = {
74 'src/app/lazy/lazy-routing.module.ts': `
75 import { NgModule } from '@angular/core';
76 import { Routes, RouterModule } from '@angular/router';
77
78 const routes: Routes = [];
79
80 @NgModule({
81 imports: [RouterModule.forChild(routes)],
82 exports: [RouterModule]
83 })
84 export class LazyRoutingModule { }
85 `,
86 'src/app/lazy/lazy.module.ts': `
87 import { NgModule } from '@angular/core';
88 import { CommonModule } from '@angular/common';
89
90 import { LazyRoutingModule } from './lazy-routing.module';
91
92 @NgModule({
93 imports: [
94 CommonModule,
95 LazyRoutingModule
96 ],
97 declarations: []
98 })
99 export class LazyModule { }
100 `,
101};
102exports.lazyModuleStringImport = {
103 'src/app/app.module.ts': `
104 import { BrowserModule } from '@angular/platform-browser';
105 import { NgModule } from '@angular/core';
106
107 import { AppComponent } from './app.component';
108 import { RouterModule } from '@angular/router';
109
110 @NgModule({
111 declarations: [
112 AppComponent
113 ],
114 imports: [
115 BrowserModule,
116 RouterModule.forRoot([
117 { path: 'lazy', loadChildren: './lazy/lazy.module#LazyModule' }
118 ])
119 ],
120 providers: [],
121 bootstrap: [AppComponent]
122 })
123 export class AppModule { }
124 `,
125};
126exports.lazyModuleFnImport = {
127 'src/app/app.module.ts': exports.lazyModuleStringImport['src/app/app.module.ts'].replace(`loadChildren: './lazy/lazy.module#LazyModule'`, `loadChildren: () => import('./lazy/lazy.module').then(m => m.LazyModule)`),
128};