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