@@ -76,7 +76,7 @@ describe('Browser Builder lazy modules', () => {
76
76
beforeEach ( done => host . initialize ( ) . subscribe ( undefined , done . fail , done ) ) ;
77
77
afterEach ( done => host . restore ( ) . subscribe ( undefined , done . fail , done ) ) ;
78
78
79
- it ( 'supports lazy bundle for lazy routes' , ( done ) => {
79
+ it ( 'supports lazy bundle for lazy routes with JIT ' , ( done ) => {
80
80
host . writeMultipleFiles ( lazyModuleFiles ) ;
81
81
host . writeMultipleFiles ( lazyModuleImport ) ;
82
82
@@ -88,6 +88,19 @@ describe('Browser Builder lazy modules', () => {
88
88
) . subscribe ( undefined , done . fail , done ) ;
89
89
} , Timeout . Basic ) ;
90
90
91
+ it ( 'supports lazy bundle for lazy routes with AOT' , ( done ) => {
92
+ host . writeMultipleFiles ( lazyModuleFiles ) ;
93
+ host . writeMultipleFiles ( lazyModuleImport ) ;
94
+
95
+ runTargetSpec ( host , browserTargetSpec , { aot : true } ) . pipe (
96
+ tap ( ( buildEvent ) => expect ( buildEvent . success ) . toBe ( true ) ) ,
97
+ tap ( ( ) => {
98
+ expect ( host . scopedSync ( )
99
+ . exists ( join ( outputPath , 'lazy-lazy-module-ngfactory.js' ) ) ) . toBe ( true ) ;
100
+ } ) ,
101
+ ) . subscribe ( undefined , done . fail , done ) ;
102
+ } , Timeout . Basic ) ;
103
+
91
104
it ( `supports lazy bundle for import() calls` , ( done ) => {
92
105
host . writeMultipleFiles ( {
93
106
'src/lazy-module.ts' : 'export const value = 42;' ,
@@ -180,7 +193,7 @@ describe('Browser Builder lazy modules', () => {
180
193
) . subscribe ( undefined , done . fail , done ) ;
181
194
} , Timeout . Basic ) ;
182
195
183
- it ( `supports extra lazy modules array` , ( done ) => {
196
+ it ( `supports extra lazy modules array in JIT ` , ( done ) => {
184
197
host . writeMultipleFiles ( lazyModuleFiles ) ;
185
198
host . writeMultipleFiles ( {
186
199
'src/app/app.component.ts' : `
@@ -210,4 +223,40 @@ describe('Browser Builder lazy modules', () => {
210
223
. toBe ( true ) ) ,
211
224
) . subscribe ( undefined , done . fail , done ) ;
212
225
} , Timeout . Basic ) ;
226
+
227
+ it ( `supports extra lazy modules array in AOT` , ( done ) => {
228
+ host . writeMultipleFiles ( lazyModuleFiles ) ;
229
+ host . writeMultipleFiles ( {
230
+ 'src/app/app.component.ts' : `
231
+ import { Component, SystemJsNgModuleLoader } from '@angular/core';
232
+
233
+ @Component({
234
+ selector: 'app-root',
235
+ templateUrl: './app.component.html',
236
+ styleUrls: ['./app.component.css'],
237
+ })
238
+ export class AppComponent {
239
+ title = 'app';
240
+ constructor(loader: SystemJsNgModuleLoader) {
241
+ // Module will be split at build time and loaded when requested below
242
+ loader.load('src/app/lazy/lazy.module#LazyModule')
243
+ .then((factory) => { /* Use factory here */ });
244
+ }
245
+ }` ,
246
+ } ) ;
247
+ host . replaceInFile ( 'src/tsconfig.app.json' , `"module": "es2015"` , `"module": "esnext"` ) ;
248
+
249
+ const overrides : Partial < BrowserBuilderSchema > = {
250
+ lazyModules : [ 'src/app/lazy/lazy.module' ] ,
251
+ aot : true ,
252
+ optimization : true ,
253
+ } ;
254
+
255
+ runTargetSpec ( host , browserTargetSpec , overrides ) . pipe (
256
+ tap ( ( buildEvent ) => expect ( buildEvent . success ) . toBe ( true ) ) ,
257
+ tap ( ( ) => expect ( host . scopedSync ( )
258
+ . exists ( join ( outputPath , 'src-app-lazy-lazy-module-ngfactory.js' ) ) )
259
+ . toBe ( true ) ) ,
260
+ ) . subscribe ( undefined , done . fail , done ) ;
261
+ } , Timeout . Basic ) ;
213
262
} ) ;
0 commit comments