5
5
* Use of this source code is governed by an MIT-style license that can be
6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
- import { readFile , replaceInFile , writeFile } from '../../utils/fs' ;
8
+ import { getGlobalVariable } from '../../utils/env' ;
9
+ import { prependToFile , readFile , replaceInFile , writeFile } from '../../utils/fs' ;
9
10
import { ng } from '../../utils/process' ;
10
- import { createProject , updateJsonFile } from '../../utils/project' ;
11
+ import { updateJsonFile } from '../../utils/project' ;
11
12
import { expectToFail } from '../../utils/utils' ;
12
13
13
14
export default async function ( ) {
14
- const projectName = 'ivy-lazy-loading' ;
15
+ const argv = getGlobalVariable ( 'argv' ) ;
16
+ const ivyProject = argv [ 'ivy' ] ;
17
+ const projectName = 'test-project' ;
15
18
const appRoutingModulePath = 'src/app/app-routing.module.ts' ;
16
19
17
- // Make Ivy project.
18
- await createProject ( projectName , '--enable-ivy' , '--routing' ) ;
20
+ // Add app routing.
21
+ // This is done automatically on a new app with --routing.
22
+ await writeFile ( './src/app-routing.module.ts' , `
23
+ import { NgModule } from '@angular/core';
24
+ import { Routes, RouterModule } from '@angular/router';
25
+
26
+ const routes: Routes = [];
27
+
28
+ @NgModule({
29
+ imports: [RouterModule.forRoot(routes)],
30
+ exports: [RouterModule]
31
+ })
32
+ export class AppRoutingModule { }
33
+ ` ) ;
34
+ await prependToFile ( 'src/app/app.module.ts' ,
35
+ `import { AppRoutingModule } from './app-routing.module';` ) ;
36
+ await replaceInFile ( 'src/app/app.module.ts' , `imports: [` , `imports: [ AppRoutingModule,` ) ;
19
37
20
38
const originalAppRoutingModule = await readFile ( appRoutingModulePath ) ;
21
39
// helper to replace loadChildren
@@ -70,6 +88,7 @@ export default async function () {
70
88
} ) ;
71
89
72
90
// Test `import()` style lazy load.
91
+ // Both Ivy and View Engine should support it.
73
92
await replaceLoadChildren ( `() => import('./lazy/lazy.module').then(m => m.LazyModule)` ) ;
74
93
await ng ( 'e2e' ) ;
75
94
await ng ( 'e2e' , '--prod' ) ;
@@ -78,13 +97,27 @@ export default async function () {
78
97
await replaceLoadChildren ( `'./lazy/lazy.module#LazyModule'` ) ;
79
98
await replaceInFile ( 'tsconfig.app.json' , `"allowEmptyCodegenFiles": false` ,
80
99
`"allowEmptyCodegenFiles": true` ) ;
81
- await expectToFail ( ( ) => ng ( 'e2e' ) ) ; // Currently broken.
82
- await ng ( 'e2e' , '--prod' ) ;
100
+ if ( ivyProject ) {
101
+ // Ivy should not support the string syntax.
102
+ await expectToFail ( ( ) => ng ( 'e2e' ) ) ;
103
+ await expectToFail ( ( ) => ng ( 'e2e' , '--prod' ) ) ;
104
+ } else {
105
+ // View engine should support the string syntax.
106
+ await ng ( 'e2e' ) ;
107
+ await ng ( 'e2e' , '--prod' ) ;
108
+ }
83
109
84
110
// Test string import without factory shims.
85
111
await replaceLoadChildren ( `'./lazy/lazy.module#LazyModule'` ) ;
86
112
await replaceInFile ( 'tsconfig.app.json' , `"allowEmptyCodegenFiles": true` ,
87
- `"allowEmptyCodegenFiles": false` ) ;
88
- await expectToFail ( ( ) => ng ( 'e2e' ) ) ; // Not supported.
89
- await expectToFail ( ( ) => ng ( 'e2e' , '--prod' ) ) ; // Not supported.
113
+ `"allowEmptyCodegenFiles": false` ) ;
114
+ if ( ivyProject ) {
115
+ // Ivy should not support the string syntax.
116
+ await expectToFail ( ( ) => ng ( 'e2e' ) ) ;
117
+ await expectToFail ( ( ) => ng ( 'e2e' , '--prod' ) ) ;
118
+ } else {
119
+ // View engine should support the string syntax.
120
+ await ng ( 'e2e' ) ;
121
+ await ng ( 'e2e' , '--prod' ) ;
122
+ }
90
123
}
0 commit comments