@@ -10,8 +10,13 @@ import { Architect } from '@angular-devkit/architect';
10
10
import { TestLogger } from '@angular-devkit/architect/testing' ;
11
11
import { take , tap , timeout } from 'rxjs/operators' ;
12
12
import {
13
- browserBuild , createArchitect , host , lazyModuleFiles ,
14
- lazyModuleFnImport , lazyModuleStringImport ,
13
+ browserBuild ,
14
+ createArchitect ,
15
+ host ,
16
+ ivyEnabled ,
17
+ lazyModuleFiles ,
18
+ lazyModuleFnImport ,
19
+ lazyModuleStringImport ,
15
20
} from '../utils' ;
16
21
17
22
// tslint:disable-next-line:no-big-function
@@ -25,10 +30,11 @@ describe('Browser Builder lazy modules', () => {
25
30
} ) ;
26
31
afterEach ( async ( ) => host . restore ( ) . toPromise ( ) ) ;
27
32
28
- for ( const [ name , imports ] of Object . entries ( {
29
- 'string' : lazyModuleStringImport ,
30
- 'function' : lazyModuleFnImport ,
31
- } ) ) {
33
+ const cases : [ string , Record < string , string > ] [ ] = [
34
+ [ 'string' , lazyModuleStringImport ] ,
35
+ [ 'function' , lazyModuleFnImport ] ,
36
+ ] ;
37
+ for ( const [ name , imports ] of cases ) {
32
38
describe ( `Load children ${ name } syntax` , ( ) => {
33
39
it ( 'supports lazy bundle for lazy routes with JIT' , async ( ) => {
34
40
host . writeMultipleFiles ( lazyModuleFiles ) ;
@@ -39,34 +45,46 @@ describe('Browser Builder lazy modules', () => {
39
45
} ) ;
40
46
41
47
it ( 'should show error when lazy route is invalid on watch mode AOT' , async ( ) => {
48
+ if ( ivyEnabled && name === 'string' ) {
49
+ pending ( 'Does not apply to Ivy.' ) ;
50
+
51
+ return ;
52
+ }
53
+
54
+ // DISABLED_FOR_IVY - These should pass but are currently not supported
55
+ if ( ivyEnabled ) {
56
+ pending ( 'Broken in Ivy' ) ;
57
+
58
+ return ;
59
+ }
60
+
42
61
host . writeMultipleFiles ( lazyModuleFiles ) ;
43
62
host . writeMultipleFiles ( imports ) ;
44
- host . replaceInFile (
45
- 'src/app/app.module.ts' ,
46
- 'lazy.module' ,
47
- 'invalid.module' ,
48
- ) ;
63
+ host . replaceInFile ( 'src/app/app.module.ts' , 'lazy.module' , 'invalid.module' ) ;
49
64
50
65
const logger = new TestLogger ( 'rebuild-lazy-errors' ) ;
51
66
const overrides = { watch : true , aot : true } ;
52
67
const run = await architect . scheduleTarget ( target , overrides , { logger } ) ;
53
- await run . output . pipe (
54
- timeout ( 15000 ) ,
55
- tap ( ( buildEvent ) => expect ( buildEvent . success ) . toBe ( false ) ) ,
56
- tap ( ( ) => {
57
- // Webpack error when using loadchildren string syntax.
58
- const hasMissingModuleError = logger . includes ( 'Could not resolve module' )
59
- // TS type error when using import().
60
- || logger . includes ( 'Cannot find module' )
61
- // Webpack error when using import() on a rebuild.
62
- // There is no TS error because the type checker is forked on rebuilds.
63
- || logger . includes ( 'Module not found' ) ;
64
- expect ( hasMissingModuleError ) . toBe ( true , 'Should show missing module error' ) ;
65
- logger . clear ( ) ;
66
- host . appendToFile ( 'src/main.ts' , ' ' ) ;
67
- } ) ,
68
- take ( 2 ) ,
69
- ) . toPromise ( ) ;
68
+ await run . output
69
+ . pipe (
70
+ timeout ( 15000 ) ,
71
+ tap ( buildEvent => expect ( buildEvent . success ) . toBe ( false ) ) ,
72
+ tap ( ( ) => {
73
+ // Webpack error when using loadchildren string syntax.
74
+ const hasMissingModuleError =
75
+ logger . includes ( 'Could not resolve module' ) ||
76
+ // TS type error when using import().
77
+ logger . includes ( 'Cannot find module' ) ||
78
+ // Webpack error when using import() on a rebuild.
79
+ // There is no TS error because the type checker is forked on rebuilds.
80
+ logger . includes ( 'Module not found' ) ;
81
+ expect ( hasMissingModuleError ) . toBe ( true , 'Should show missing module error' ) ;
82
+ logger . clear ( ) ;
83
+ host . appendToFile ( 'src/main.ts' , ' ' ) ;
84
+ } ) ,
85
+ take ( 2 ) ,
86
+ )
87
+ . toPromise ( ) ;
70
88
await run . stop ( ) ;
71
89
} ) ;
72
90
@@ -75,7 +93,13 @@ describe('Browser Builder lazy modules', () => {
75
93
host . writeMultipleFiles ( imports ) ;
76
94
77
95
const { files } = await browserBuild ( architect , host , target , { aot : true } ) ;
78
- expect ( files [ 'lazy-lazy-module-ngfactory.js' ] ) . not . toBeUndefined ( ) ;
96
+ if ( ivyEnabled ) {
97
+ const data = await files [ 'lazy-lazy-module.js' ] ;
98
+ expect ( data ) . not . toBeUndefined ( 'Lazy module output bundle does not exist' ) ;
99
+ expect ( data ) . toContain ( 'LazyModule.ngModuleDef' ) ;
100
+ } else {
101
+ expect ( files [ 'lazy-lazy-module-ngfactory.js' ] ) . not . toBeUndefined ( ) ;
102
+ }
79
103
} ) ;
80
104
} ) ;
81
105
}
@@ -206,8 +230,14 @@ describe('Browser Builder lazy modules', () => {
206
230
const { files } = await browserBuild ( architect , host , target , {
207
231
lazyModules : [ 'src/app/lazy/lazy.module' ] ,
208
232
aot : true ,
209
- optimization : true ,
210
233
} ) ;
211
- expect ( files [ 'src-app-lazy-lazy-module-ngfactory.js' ] ) . not . toBeUndefined ( ) ;
234
+
235
+ if ( ivyEnabled ) {
236
+ const data = await files [ 'src-app-lazy-lazy-module.js' ] ;
237
+ expect ( data ) . not . toBeUndefined ( 'Lazy module output bundle does not exist' ) ;
238
+ expect ( data ) . toContain ( 'LazyModule.ngModuleDef' ) ;
239
+ } else {
240
+ expect ( files [ 'src-app-lazy-lazy-module-ngfactory.js' ] ) . not . toBeUndefined ( ) ;
241
+ }
212
242
} ) ;
213
243
} ) ;
0 commit comments