@@ -45,6 +45,14 @@ describe('Browser Builder lazy modules', () => {
45
45
) ;
46
46
}
47
47
48
+ function hasMissingModuleError ( logger : TestLogger ) {
49
+ // TS type error when using import().
50
+ return logger . includes ( 'Cannot find module' ) ||
51
+ // Webpack error when using import() on a rebuild.
52
+ // There is no TS error because the type checker is forked on rebuilds.
53
+ logger . includes ( 'Module not found' ) ;
54
+ }
55
+
48
56
const cases : [ string , Record < string , string > ] [ ] = [
49
57
[ 'string' , lazyModuleStringImport ] ,
50
58
[ 'function' , lazyModuleFnImport ] ,
@@ -63,50 +71,6 @@ describe('Browser Builder lazy modules', () => {
63
71
expect ( 'lazy-lazy-module.js' in files ) . toBe ( true ) ;
64
72
} ) ;
65
73
66
- it ( 'should show error when lazy route is invalid on watch mode AOT' , async ( ) => {
67
- if ( ! veEnabled && name === 'string' ) {
68
- pending ( 'Does not apply to Ivy.' ) ;
69
-
70
- return ;
71
- }
72
-
73
- // DISABLED_FOR_IVY - These should pass but are currently not supported
74
- if ( ! veEnabled ) {
75
- pending ( 'Broken in Ivy' ) ;
76
-
77
- return ;
78
- }
79
-
80
- host . writeMultipleFiles ( lazyModuleFiles ) ;
81
- host . writeMultipleFiles ( imports ) ;
82
- host . replaceInFile ( 'src/app/app.module.ts' , 'lazy.module' , 'invalid.module' ) ;
83
-
84
- const logger = new TestLogger ( 'rebuild-lazy-errors' ) ;
85
- const overrides = { watch : true , aot : true } ;
86
- const run = await architect . scheduleTarget ( target , overrides , { logger } ) ;
87
- await run . output
88
- . pipe (
89
- timeout ( 15000 ) ,
90
- tap ( buildEvent => expect ( buildEvent . success ) . toBe ( false ) ) ,
91
- tap ( ( ) => {
92
- // Webpack error when using loadchildren string syntax.
93
- const hasMissingModuleError =
94
- logger . includes ( 'Could not resolve module' ) ||
95
- // TS type error when using import().
96
- logger . includes ( 'Cannot find module' ) ||
97
- // Webpack error when using import() on a rebuild.
98
- // There is no TS error because the type checker is forked on rebuilds.
99
- logger . includes ( 'Module not found' ) ;
100
- expect ( hasMissingModuleError ) . toBe ( true , 'Should show missing module error' ) ;
101
- logger . clear ( ) ;
102
- host . appendToFile ( 'src/main.ts' , ' ' ) ;
103
- } ) ,
104
- take ( 2 ) ,
105
- )
106
- . toPromise ( ) ;
107
- await run . stop ( ) ;
108
- } ) ;
109
-
110
74
it ( 'supports lazy bundle for lazy routes with AOT' , async ( ) => {
111
75
host . writeMultipleFiles ( lazyModuleFiles ) ;
112
76
host . writeMultipleFiles ( imports ) ;
@@ -124,6 +88,52 @@ describe('Browser Builder lazy modules', () => {
124
88
} ) ;
125
89
}
126
90
91
+ // Errors for missing lazy routes are only supported with function syntax.
92
+ // `ngProgram.listLazyRoutes` will ignore invalid lazy routes in the route map.
93
+ describe ( `Load children errors with function syntax` , ( ) => {
94
+ it ( 'should show error when lazy route is invalid' , async ( ) => {
95
+ host . writeMultipleFiles ( lazyModuleFiles ) ;
96
+ host . writeMultipleFiles ( lazyModuleFnImport ) ;
97
+ host . replaceInFile ( 'src/app/app.module.ts' , 'lazy.module' , 'invalid.module' ) ;
98
+
99
+ const logger = new TestLogger ( 'build-lazy-errors' ) ;
100
+ const run = await architect . scheduleTarget ( target , { } , { logger } ) ;
101
+ const output = await run . result ;
102
+ expect ( output . success ) . toBe ( false ) ;
103
+ expect ( hasMissingModuleError ( logger ) ) . toBe ( true , 'Should show missing module error' ) ;
104
+ } ) ;
105
+
106
+ it ( 'should show error when lazy route is invalid on watch mode AOT' , async ( ) => {
107
+ host . writeMultipleFiles ( lazyModuleFiles ) ;
108
+ host . writeMultipleFiles ( lazyModuleFnImport ) ;
109
+
110
+ let buildNumber = 0 ;
111
+ const logger = new TestLogger ( 'rebuild-lazy-errors' ) ;
112
+ const overrides = { watch : true , aot : true } ;
113
+ const run = await architect . scheduleTarget ( target , overrides , { logger } ) ;
114
+ await run . output
115
+ . pipe (
116
+ timeout ( 15000 ) ,
117
+ tap ( buildEvent => {
118
+ buildNumber ++ ;
119
+ switch ( buildNumber ) {
120
+ case 1 :
121
+ expect ( buildEvent . success ) . toBe ( true ) ;
122
+ host . replaceInFile ( 'src/app/app.module.ts' , 'lazy.module' , 'invalid.module' ) ;
123
+ logger . clear ( ) ;
124
+ break ;
125
+ case 2 :
126
+ expect ( buildEvent . success ) . toBe ( false ) ;
127
+ break ;
128
+ }
129
+ } ) ,
130
+ take ( 2 ) ,
131
+ )
132
+ . toPromise ( ) ;
133
+ await run . stop ( ) ;
134
+ } ) ;
135
+ } ) ;
136
+
127
137
it ( `supports lazy bundle for import() calls` , async ( ) => {
128
138
host . writeMultipleFiles ( {
129
139
'src/lazy-module.ts' : 'export const value = 42;' ,
0 commit comments