@@ -3,14 +3,20 @@ import {
3
3
waitForAnyProcessOutputToMatch ,
4
4
execAndWaitForOutputToMatch ,
5
5
} 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' ;
8
9
9
10
10
11
const failedRe = / w e b p a c k : F a i l e d t o c o m p i l e / ;
11
12
const 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
+ ] ;
12
18
13
- export default function ( ) {
19
+ export default function ( ) {
14
20
if ( process . platform . startsWith ( 'win' ) ) {
15
21
return Promise . resolve ( ) ;
16
22
}
@@ -19,16 +25,77 @@ export default function() {
19
25
return Promise . resolve ( ) ;
20
26
}
21
27
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
+
22
35
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' , '' ) )
25
41
// 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.
28
74
. then ( ( ) => Promise . all ( [
29
75
waitForAnyProcessOutputToMatch ( successRe , 20000 ) ,
30
76
replaceInFile ( 'src/app/app.component.ts' , ']]]]]' , '' )
31
77
] ) )
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
+ ] ) )
32
99
. then ( ( ) => killAllProcesses ( ) , ( err : any ) => {
33
100
killAllProcesses ( ) ;
34
101
throw err ;
0 commit comments