@@ -3,14 +3,20 @@ import {
33 waitForAnyProcessOutputToMatch ,
44 execAndWaitForOutputToMatch ,
55} from '../../utils/process' ;
6- import { replaceInFile , appendToFile } from '../../utils/fs' ;
7- import { getGlobalVariable } from '../../utils/env' ;
6+ import { replaceInFile , readFile , writeFile } from '../../utils/fs' ;
7+ import { getGlobalVariable } from '../../utils/env' ;
8+ import { wait } from '../../utils/utils' ;
89
910
1011const failedRe = / w e b p a c k : F a i l e d t o c o m p i l e / ;
1112const successRe = / 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 / ;
13+ const extraErrors = [
14+ `Final loader didn't return a Buffer or String` ,
15+ `doesn't contain a valid alias configuration` ,
16+ `main.ts is not part of the TypeScript compilation.` ,
17+ ] ;
1218
13- export default function ( ) {
19+ export default function ( ) {
1420 if ( process . platform . startsWith ( 'win' ) ) {
1521 return Promise . resolve ( ) ;
1622 }
@@ -19,16 +25,77 @@ export default function() {
1925 return Promise . resolve ( ) ;
2026 }
2127
28+ // Skip in non-nightly tests. Switch this check around when ng5 is out.
29+ if ( ! getGlobalVariable ( 'argv' ) . nightly ) {
30+ return Promise . resolve ( ) ;
31+ }
32+
33+ let origContent : string ;
34+
2235 return Promise . resolve ( )
23- // Add an error to a non-main file.
24- . then ( ( ) => appendToFile ( 'src/app/app.component.ts' , ']]]]]' ) )
36+ // Save the original contents of `./src/app/app.component.ts`.
37+ . then ( ( ) => readFile ( './src/app/app.component.ts' ) )
38+ . then ( ( contents ) => origContent = contents )
39+ // Add a major error on a non-main file to the initial build.
40+ . then ( ( ) => writeFile ( 'src/app/app.component.ts' , '' ) )
2541 // Should have an error.
26- . then ( ( ) => execAndWaitForOutputToMatch ( 'ng' , [ 'serve' ] , failedRe ) )
27- // Fix the error, should trigger a rebuild.
42+ . then ( ( ) => execAndWaitForOutputToMatch ( 'ng' , [ 'serve' , '--aot' ] , failedRe ) )
43+ . then ( ( results ) => {
44+ const stderr = results . stderr ;
45+ if ( ! stderr . includes ( `Unexpected value 'AppComponent` ) ) {
46+ throw new Error ( `Expected static analysis error, got this instead:\n${ stderr } ` ) ;
47+ }
48+ if ( extraErrors . some ( ( e ) => stderr . includes ( e ) ) ) {
49+ throw new Error ( `Did not expect extra errors but got:\n${ stderr } ` ) ;
50+ }
51+ } )
52+ // Fix the error, should trigger a successful rebuild.
53+ . then ( ( ) => Promise . all ( [
54+ waitForAnyProcessOutputToMatch ( successRe , 20000 ) ,
55+ writeFile ( 'src/app/app.component.ts' , origContent )
56+ ] ) )
57+ . then ( ( ) => wait ( 2000 ) )
58+ // Add an syntax error to a non-main file.
59+ // Build should still be successfull and error reported on forked type checker.
60+ . then ( ( ) => Promise . all ( [
61+ waitForAnyProcessOutputToMatch ( successRe , 20000 ) ,
62+ writeFile ( 'src/app/app.component.ts' , origContent + '\n]]]]]' )
63+ ] ) )
64+ . then ( ( results ) => {
65+ const stderr = results [ 0 ] . stderr ;
66+ if ( ! stderr . includes ( 'Declaration or statement expected.' ) ) {
67+ throw new Error ( `Expected syntax error, got this instead:\n${ stderr } ` ) ;
68+ }
69+ if ( extraErrors . some ( ( e ) => stderr . includes ( e ) ) ) {
70+ throw new Error ( `Did not expect extra errors but got:\n${ stderr } ` ) ;
71+ }
72+ } )
73+ // Fix the error, should trigger a successful rebuild.
2874 . then ( ( ) => Promise . all ( [
2975 waitForAnyProcessOutputToMatch ( successRe , 20000 ) ,
3076 replaceInFile ( 'src/app/app.component.ts' , ']]]]]' , '' )
3177 ] ) )
78+ . then ( ( ) => wait ( 2000 ) )
79+ // Add a major error on a rebuild.
80+ // Should fail the rebuild.
81+ . then ( ( ) => Promise . all ( [
82+ waitForAnyProcessOutputToMatch ( failedRe , 20000 ) ,
83+ writeFile ( 'src/app/app.component.ts' , '' )
84+ ] ) )
85+ . then ( ( results ) => {
86+ const stderr = results [ 0 ] . stderr ;
87+ if ( ! stderr . includes ( `Unexpected value 'AppComponent` ) ) {
88+ throw new Error ( `Expected static analysis error, got this instead:\n${ stderr } ` ) ;
89+ }
90+ if ( extraErrors . some ( ( e ) => stderr . includes ( e ) ) ) {
91+ throw new Error ( `Did not expect extra errors but got:\n${ stderr } ` ) ;
92+ }
93+ } )
94+ // Fix the error, should trigger a successful rebuild.
95+ . then ( ( ) => Promise . all ( [
96+ waitForAnyProcessOutputToMatch ( successRe , 20000 ) ,
97+ writeFile ( 'src/app/app.component.ts' , origContent )
98+ ] ) )
3299 . then ( ( ) => killAllProcesses ( ) , ( err : any ) => {
33100 killAllProcesses ( ) ;
34101 throw err ;
0 commit comments