UNPKG

4.97 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');
15if (exports.ivyEnabled) {
16 // tslint:disable-next-line:no-console
17 console.warn('********* IVY Enabled ***********');
18}
19const devkitRoot = core_1.normalize(global._DevKitRoot); // tslint:disable-line:no-any
20exports.workspaceRoot = core_1.join(devkitRoot, `tests/angular_devkit/build_angular/hello-world-app${exports.ivyEnabled ? '-ivy' : ''}/`);
21exports.host = new testing_1.TestProjectHost(exports.workspaceRoot);
22exports.outputPath = core_1.normalize('dist');
23exports.browserTargetSpec = { project: 'app', target: 'build' };
24exports.devServerTargetSpec = { project: 'app', target: 'serve' };
25exports.extractI18nTargetSpec = { project: 'app', target: 'extract-i18n' };
26exports.karmaTargetSpec = { project: 'app', target: 'test' };
27exports.tslintTargetSpec = { project: 'app', target: 'lint' };
28exports.protractorTargetSpec = { project: 'app-e2e', target: 'e2e' };
29async 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}
42exports.createArchitect = createArchitect;
43async 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}
76exports.browserBuild = browserBuild;
77exports.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};
106exports.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};
130exports.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};