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