1
1
import { readdirSync } from 'fs' ;
2
2
import { oneLine } from 'common-tags' ;
3
3
4
- import { ng } from '../../utils/process' ;
4
+ import { ng , npm } from '../../utils/process' ;
5
5
import { addImportToModule } from '../../utils/ast' ;
6
+ import { appendToFile , writeFile } from '../../utils/fs' ;
6
7
7
8
8
9
export default function ( ) {
@@ -21,13 +22,43 @@ export default function() {
21
22
if ( oldNumberOfFiles >= currentNumberOfDistFiles ) {
22
23
throw new Error ( 'A bundle for the lazy module was not created.' ) ;
23
24
}
25
+ oldNumberOfFiles = currentNumberOfDistFiles ;
26
+ } )
27
+ // verify System.import still works
28
+ . then ( ( ) => writeFile ( 'src/app/lazy-file.ts' , '' ) )
29
+ . then ( ( ) => appendToFile ( 'src/app/app.component.ts' , `
30
+ // verify other System.import still work
31
+ declare var System: any;
32
+ const lazyFile = 'file';
33
+ System.import('./lazy-' + lazyFile);
34
+ ` ) )
35
+ . then ( ( ) => ng ( 'build' ) )
36
+ . then ( ( ) => readdirSync ( 'dist' ) . length )
37
+ . then ( currentNumberOfDistFiles => {
38
+ if ( oldNumberOfFiles >= currentNumberOfDistFiles ) {
39
+ throw new Error ( 'A bundle for the lazy file was not created.' ) ;
40
+ }
41
+ oldNumberOfFiles = currentNumberOfDistFiles ;
42
+ } )
43
+ // verify 'import *' syntax doesn't break lazy modules
44
+ . then ( ( ) => npm ( 'install' , 'moment' ) )
45
+ . then ( ( ) => appendToFile ( 'src/app/app.component.ts' , `
46
+ import * as moment from 'moment';
47
+ console.log(moment);
48
+ ` ) )
49
+ . then ( ( ) => ng ( 'build' ) )
50
+ . then ( ( ) => readdirSync ( 'dist' ) . length )
51
+ . then ( currentNumberOfDistFiles => {
52
+ if ( oldNumberOfFiles != currentNumberOfDistFiles ) {
53
+ throw new Error ( 'Bundles were not created after adding \'import *\'.' ) ;
54
+ }
24
55
} )
25
56
// Check for AoT and lazy routes.
26
57
. then ( ( ) => ng ( 'build' , '--aot' ) )
27
58
. then ( ( ) => readdirSync ( 'dist' ) . length )
28
59
. then ( currentNumberOfDistFiles => {
29
- if ( oldNumberOfFiles > = currentNumberOfDistFiles ) {
30
- throw new Error ( 'A bundle for the lazy module was not created .' ) ;
60
+ if ( oldNumberOfFiles ! = currentNumberOfDistFiles ) {
61
+ throw new Error ( 'AoT build contains a different number of files .' ) ;
31
62
}
32
63
} ) ;
33
64
}
0 commit comments