source: trip-planner-front/node_modules/@angular-devkit/build-angular/src/test-utils.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 4.9 KB
Line 
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.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;
11const architect_1 = require("@angular-devkit/architect");
12const node_1 = require("@angular-devkit/architect/node");
13const testing_1 = require("@angular-devkit/architect/testing");
14const core_1 = require("@angular-devkit/core");
15// Default timeout for large specs is 2.5 minutes.
16jasmine.DEFAULT_TIMEOUT_INTERVAL = 150000;
17exports.workspaceRoot = core_1.join(core_1.normalize(__dirname), `../test/hello-world-app/`);
18exports.host = new testing_1.TestProjectHost(exports.workspaceRoot);
19exports.outputPath = core_1.normalize('dist');
20exports.browserTargetSpec = { project: 'app', target: 'build' };
21exports.devServerTargetSpec = { project: 'app', target: 'serve' };
22exports.extractI18nTargetSpec = { project: 'app', target: 'extract-i18n' };
23exports.karmaTargetSpec = { project: 'app', target: 'test' };
24exports.tslintTargetSpec = { project: 'app', target: 'lint' };
25exports.protractorTargetSpec = { project: 'app-e2e', target: 'e2e' };
26async 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}
39exports.createArchitect = createArchitect;
40async 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}
80exports.browserBuild = browserBuild;
81exports.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};
110exports.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};
Note: See TracBrowser for help on using the repository browser.