11import {
22 killAllProcesses ,
3- exec ,
43 waitForAnyProcessOutputToMatch ,
54 execAndWaitForOutputToMatch ,
65 ng ,
@@ -11,7 +10,6 @@ import {request} from '../../utils/http';
1110import { getGlobalVariable } from '../../utils/env' ;
1211
1312const 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 .../ ;
1513
1614export default function ( ) {
1715 if ( process . platform . startsWith ( 'win' ) ) {
@@ -26,95 +24,96 @@ export default function() {
2624 const chunkRegExp = / c h u n k \s + \{ / g;
2725
2826 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 ) )
3327 // Count the bundles.
3428 . then ( ( { stdout } ) => {
3529 oldNumberOfChunks = stdout . split ( chunkRegExp ) . length ;
3630 } )
3731 // Add a lazy module.
3832 . 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';
46-
47- import { AppComponent } from './app.component';
48- import { RouterModule } from '@angular/router';
49-
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- ` ) )
6733 // Should trigger a rebuild with a new bundle.
68- . then ( ( ) => waitForAnyProcessOutputToMatch ( validBundleRegEx , 10000 ) )
69- // Count the bundles.
70- . then ( ( { stdout } ) => {
71- let newNumberOfChunks = stdout . split ( chunkRegExp ) . length ;
72- if ( oldNumberOfChunks >= newNumberOfChunks ) {
73- throw new Error ( 'Expected webpack to create a new chunk, but did not.' ) ;
74- }
75- } )
76- // Change multiple files and check that all of them are invalidated and recompiled.
77- . then ( ( ) => writeMultipleFiles ( {
78- 'src/app/app.module.ts' : `
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' , `
7939 import { BrowserModule } from '@angular/platform-browser';
8040 import { NgModule } from '@angular/core';
41+ import { FormsModule } from '@angular/forms';
42+ import { HttpModule } from '@angular/http';
8143
8244 import { AppComponent } from './app.component';
45+ import { RouterModule } from '@angular/router';
8346
8447 @NgModule({
8548 declarations: [
8649 AppComponent
8750 ],
8851 imports: [
89- BrowserModule
52+ BrowserModule,
53+ FormsModule,
54+ HttpModule,
55+ RouterModule.forRoot([
56+ { path: 'lazy', loadChildren: './lazy/lazy.module#LazyModule' }
57+ ])
9058 ],
9159 providers: [],
9260 bootstrap: [AppComponent]
9361 })
9462 export class AppModule { }
63+ ` )
64+ ] ) )
65+ // Count the bundles.
66+ . then ( ( results ) => {
67+ const stdout = results [ 0 ] . stdout ;
68+ let newNumberOfChunks = stdout . split ( chunkRegExp ) . length ;
69+ if ( oldNumberOfChunks >= newNumberOfChunks ) {
70+ throw new Error ( 'Expected webpack to create a new chunk, but did not.' ) ;
71+ }
72+ } )
73+ // Change multiple files and check that all of them are invalidated and recompiled.
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';
9582
96- console.log('$$_E2E_GOLDEN_VALUE_1');
97- export let X = '$$_E2E_GOLDEN_VALUE_2';
98- ` ,
99- 'src/main.ts' : `
100- import { enableProdMode } from '@angular/core';
101- import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
83+ @NgModule({
84+ declarations: [
85+ AppComponent
86+ ],
87+ imports: [
88+ BrowserModule
89+ ],
90+ providers: [],
91+ bootstrap: [AppComponent]
92+ })
93+ export class AppModule { }
10294
103- import { AppModule } from './app/app.module';
104- import { environment } from './environments/environment';
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';
105101
106- if (environment.production) {
107- enableProdMode();
108- }
102+ import { AppModule } from './app/app.module';
103+ import { environment } from './environments/environment';
109104
110- platformBrowserDynamic().bootstrapModule(AppModule);
105+ if (environment.production) {
106+ enableProdMode();
107+ }
111108
112- import * as m from './app/app.module';
113- console.log(m.X);
114- console.log('$$_E2E_GOLDEN_VALUE_3');
115- `
116- } ) )
117- . then ( ( ) => waitForAnyProcessOutputToMatch ( validBundleRegEx , 10000 ) )
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+ ] ) )
118117 . then ( ( ) => wait ( 2000 ) )
119118 . then ( ( ) => request ( 'http://localhost:4200/main.bundle.js' ) )
120119 . then ( ( body ) => {
0 commit comments