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