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.veEnabled = process.argv.includes('--ve');
|
15 | const devkitRoot = core_1.normalize(global._DevKitRoot);
|
16 | exports.workspaceRoot = core_1.join(devkitRoot, `tests/angular_devkit/build_angular/hello-world-app${exports.veEnabled ? '-ve' : ''}/`);
|
17 | exports.host = new testing_1.TestProjectHost(exports.workspaceRoot);
|
18 | exports.outputPath = core_1.normalize('dist');
|
19 | exports.browserTargetSpec = { project: 'app', target: 'build' };
|
20 | exports.devServerTargetSpec = { project: 'app', target: 'serve' };
|
21 | exports.extractI18nTargetSpec = { project: 'app', target: 'extract-i18n' };
|
22 | exports.karmaTargetSpec = { project: 'app', target: 'test' };
|
23 | exports.tslintTargetSpec = { project: 'app', target: 'lint' };
|
24 | exports.protractorTargetSpec = { project: 'app-e2e', target: 'e2e' };
|
25 | async 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.workspaces.readWorkspace(workspaceSysPath, core_1.workspaces.createWorkspaceHost(exports.host));
|
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 | }
|
38 | exports.createArchitect = createArchitect;
|
39 | async 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.outputPaths[0]).not.toBeUndefined();
|
44 | const outputPath = core_1.normalize(output.outputPaths[0]);
|
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 | }
|
72 | exports.browserBuild = browserBuild;
|
73 | exports.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 | };
|
102 | exports.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 | };
|
126 | exports.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 | };
|