forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrebuild.ts
More file actions
128 lines (115 loc) · 4.03 KB
/
rebuild.ts
File metadata and controls
128 lines (115 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import {
killAllProcesses,
waitForAnyProcessOutputToMatch,
execAndWaitForOutputToMatch,
ng,
} from '../../utils/process';
import {writeFile, writeMultipleFiles} from '../../utils/fs';
import {wait} from '../../utils/utils';
import {request} from '../../utils/http';
import {getGlobalVariable} from '../../utils/env';
const validBundleRegEx = /: Compiled successfully./;
export default function() {
if (process.platform.startsWith('win')) {
return Promise.resolve();
}
// Skip this in ejected tests.
if (getGlobalVariable('argv').eject) {
return Promise.resolve();
}
const lazyChunkRegExp = /lazy-module\.js/g;
return execAndWaitForOutputToMatch('ng', ['serve'], validBundleRegEx)
// Add a lazy module.
.then(() => ng('generate', 'module', 'lazy', '--routing'))
// Should trigger a rebuild with a new bundle.
// We need to use Promise.all to ensure we are waiting for the rebuild just before we write
// the file, otherwise rebuilds can be too fast and fail CI.
.then(() => Promise.all([
waitForAnyProcessOutputToMatch(validBundleRegEx, 10000),
writeFile('src/app/app.module.ts', `
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { RouterModule } from '@angular/router';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
RouterModule.forRoot([
{ path: 'lazy', loadChildren: './lazy/lazy.module#LazyModule' }
])
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
`)
]))
// Count the bundles.
.then((results) => {
const stdout = results[0].stdout;
if (!lazyChunkRegExp.test(stdout)) {
throw new Error('Expected webpack to create a new chunk, but did not.');
}
})
// Change multiple files and check that all of them are invalidated and recompiled.
.then(() => Promise.all([
waitForAnyProcessOutputToMatch(validBundleRegEx, 10000),
writeMultipleFiles({
'src/app/app.module.ts': `
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
console.log('$$_E2E_GOLDEN_VALUE_1');
export let X = '$$_E2E_GOLDEN_VALUE_2';
`,
'src/main.ts': `
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule);
import * as m from './app/app.module';
console.log(m.X);
console.log('$$_E2E_GOLDEN_VALUE_3');
`
})
]))
.then(() => wait(2000))
.then(() => request('http://localhost:4200/main.js'))
.then((body) => {
if (!body.match(/\$\$_E2E_GOLDEN_VALUE_1/)) {
throw new Error('Expected golden value 1.');
}
if (!body.match(/\$\$_E2E_GOLDEN_VALUE_2/)) {
throw new Error('Expected golden value 2.');
}
if (!body.match(/\$\$_E2E_GOLDEN_VALUE_3/)) {
throw new Error('Expected golden value 3.');
}
})
.then(() => killAllProcesses(), (err: any) => {
killAllProcesses();
throw err;
});
}