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,66 +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';
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';
4643
47- import { AppComponent } from './app.component';
48- import { RouterModule } from '@angular/router';
44+ import { AppComponent } from './app.component';
45+ import { RouterModule } from '@angular/router';
4946
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+ ] ) )
6965 // Count the bundles.
70- . then ( ( { stdout } ) => {
66+ . then ( ( results ) => {
67+ const stdout = results [ 0 ] . stdout ;
7168 let newNumberOfChunks = stdout . split ( chunkRegExp ) . length ;
7269 if ( oldNumberOfChunks >= newNumberOfChunks ) {
7370 throw new Error ( 'Expected webpack to create a new chunk, but did not.' ) ;
7471 }
7572 } )
7673 // 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+ ] ) )
89117 . then ( ( ) => wait ( 2000 ) )
90118 . then ( ( ) => request ( 'http://localhost:4200/main.bundle.js' ) )
91119 . then ( ( body ) => {
0 commit comments