1
1
import {
2
2
killAllProcesses ,
3
- exec ,
4
3
waitForAnyProcessOutputToMatch ,
5
4
execAndWaitForOutputToMatch ,
6
5
ng ,
@@ -11,7 +10,6 @@ import {request} from '../../utils/http';
11
10
import { getGlobalVariable } from '../../utils/env' ;
12
11
13
12
const validBundleRegEx = / w e b p a c k : b u n d l e i s n o w V A L I D | w e b p a c k : C o m p i l e d s u c c e s s f u l l y ./ ;
14
- const invalidBundleRegEx = / w e b p a c k : b u n d l e i s n o w I N V A L I D | w e b p a c k : C o m p i l i n g .../ ;
15
13
16
14
export default function ( ) {
17
15
if ( process . platform . startsWith ( 'win' ) ) {
@@ -26,66 +24,96 @@ export default function() {
26
24
const chunkRegExp = / c h u n k \s + \{ / g;
27
25
28
26
return execAndWaitForOutputToMatch ( 'ng' , [ 'serve' ] , validBundleRegEx )
29
- // Should trigger a rebuild.
30
- . then ( ( ) => exec ( 'touch' , 'src/main.ts' ) )
31
- . then ( ( ) => waitForAnyProcessOutputToMatch ( invalidBundleRegEx , 10000 ) )
32
- . then ( ( ) => waitForAnyProcessOutputToMatch ( validBundleRegEx , 10000 ) )
33
27
// Count the bundles.
34
28
. then ( ( { stdout } ) => {
35
29
oldNumberOfChunks = stdout . split ( chunkRegExp ) . length ;
36
30
} )
37
31
// Add a lazy module.
38
32
. then ( ( ) => ng ( 'generate' , 'module' , 'lazy' , '--routing' ) )
39
- // Just wait for the rebuild, otherwise we might be validating the last build.
40
- . then ( ( ) => waitForAnyProcessOutputToMatch ( validBundleRegEx , 10000 ) )
41
- . then ( ( ) => writeFile ( 'src/app/app.module.ts' , `
42
- import { BrowserModule } from '@angular/platform-browser';
43
- import { NgModule } from '@angular/core';
44
- import { FormsModule } from '@angular/forms';
45
- import { HttpModule } from '@angular/http';
33
+ // Should trigger a rebuild with a new bundle.
34
+ // We need to use Promise.all to ensure we are waiting for the rebuild just before we write
35
+ // the file, otherwise rebuilds can be too fast and fail CI.
36
+ . then ( ( ) => Promise . all ( [
37
+ waitForAnyProcessOutputToMatch ( validBundleRegEx , 10000 ) ,
38
+ writeFile ( 'src/app/app.module.ts' , `
39
+ import { BrowserModule } from '@angular/platform-browser';
40
+ import { NgModule } from '@angular/core';
41
+ import { FormsModule } from '@angular/forms';
42
+ import { HttpModule } from '@angular/http';
46
43
47
- import { AppComponent } from './app.component';
48
- import { RouterModule } from '@angular/router';
44
+ import { AppComponent } from './app.component';
45
+ import { RouterModule } from '@angular/router';
49
46
50
- @NgModule({
51
- declarations: [
52
- AppComponent
53
- ],
54
- imports: [
55
- BrowserModule,
56
- FormsModule,
57
- HttpModule,
58
- RouterModule.forRoot([
59
- { path: 'lazy', loadChildren: './lazy/lazy.module#LazyModule' }
60
- ])
61
- ],
62
- providers: [],
63
- bootstrap: [AppComponent]
64
- })
65
- export class AppModule { }
66
- ` ) )
67
- // Should trigger a rebuild with a new bundle.
68
- . then ( ( ) => waitForAnyProcessOutputToMatch ( validBundleRegEx , 10000 ) )
47
+ @NgModule({
48
+ declarations: [
49
+ AppComponent
50
+ ],
51
+ imports: [
52
+ BrowserModule,
53
+ FormsModule,
54
+ HttpModule,
55
+ RouterModule.forRoot([
56
+ { path: 'lazy', loadChildren: './lazy/lazy.module#LazyModule' }
57
+ ])
58
+ ],
59
+ providers: [],
60
+ bootstrap: [AppComponent]
61
+ })
62
+ export class AppModule { }
63
+ ` )
64
+ ] ) )
69
65
// Count the bundles.
70
- . then ( ( { stdout } ) => {
66
+ . then ( ( results ) => {
67
+ const stdout = results [ 0 ] . stdout ;
71
68
let newNumberOfChunks = stdout . split ( chunkRegExp ) . length ;
72
69
if ( oldNumberOfChunks >= newNumberOfChunks ) {
73
70
throw new Error ( 'Expected webpack to create a new chunk, but did not.' ) ;
74
71
}
75
72
} )
76
73
// Change multiple files and check that all of them are invalidated and recompiled.
77
- . then ( ( ) => writeMultipleFiles ( {
78
- 'src/app/app.module.ts' : `
79
- console.log('$$_E2E_GOLDEN_VALUE_1');
80
- export let X = '$$_E2E_GOLDEN_VALUE_2';
81
- ` ,
82
- 'src/main.ts' : `
83
- import * as m from './app/app.module';
84
- console.log(m.X);
85
- console.log('$$_E2E_GOLDEN_VALUE_3');
86
- `
87
- } ) )
88
- . then ( ( ) => waitForAnyProcessOutputToMatch ( validBundleRegEx , 10000 ) )
74
+ . then ( ( ) => Promise . all ( [
75
+ waitForAnyProcessOutputToMatch ( validBundleRegEx , 10000 ) ,
76
+ writeMultipleFiles ( {
77
+ 'src/app/app.module.ts' : `
78
+ import { BrowserModule } from '@angular/platform-browser';
79
+ import { NgModule } from '@angular/core';
80
+
81
+ import { AppComponent } from './app.component';
82
+
83
+ @NgModule({
84
+ declarations: [
85
+ AppComponent
86
+ ],
87
+ imports: [
88
+ BrowserModule
89
+ ],
90
+ providers: [],
91
+ bootstrap: [AppComponent]
92
+ })
93
+ export class AppModule { }
94
+
95
+ console.log('$$_E2E_GOLDEN_VALUE_1');
96
+ export let X = '$$_E2E_GOLDEN_VALUE_2';
97
+ ` ,
98
+ 'src/main.ts' : `
99
+ import { enableProdMode } from '@angular/core';
100
+ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
101
+
102
+ import { AppModule } from './app/app.module';
103
+ import { environment } from './environments/environment';
104
+
105
+ if (environment.production) {
106
+ enableProdMode();
107
+ }
108
+
109
+ platformBrowserDynamic().bootstrapModule(AppModule);
110
+
111
+ import * as m from './app/app.module';
112
+ console.log(m.X);
113
+ console.log('$$_E2E_GOLDEN_VALUE_3');
114
+ `
115
+ } )
116
+ ] ) )
89
117
. then ( ( ) => wait ( 2000 ) )
90
118
. then ( ( ) => request ( 'http://localhost:4200/main.bundle.js' ) )
91
119
. then ( ( body ) => {
0 commit comments