Skip to content

Commit 680946d

Browse files
committed
test: test lazy-loading syntax for VE and Ivy
1 parent 430c003 commit 680946d

File tree

1 file changed

+53
-15
lines changed

1 file changed

+53
-15
lines changed

tests/legacy-cli/e2e/tests/ivy/ivy-lazy-load.ts renamed to tests/legacy-cli/e2e/tests/build/lazy-load-syntax.ts

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,35 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { readFile, replaceInFile, writeFile } from '../../utils/fs';
8+
import { getGlobalVariable } from '../../utils/env';
9+
import { prependToFile, readFile, replaceInFile, writeFile } from '../../utils/fs';
910
import { ng } from '../../utils/process';
10-
import { createProject, updateJsonFile } from '../../utils/project';
11+
import { updateJsonFile } from '../../utils/project';
1112
import { expectToFail } from '../../utils/utils';
1213

1314
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';
1518
const appRoutingModulePath = 'src/app/app-routing.module.ts';
1619

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(appRoutingModulePath, `
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,`);
1937

2038
const originalAppRoutingModule = await readFile(appRoutingModulePath);
2139
// helper to replace loadChildren
@@ -69,22 +87,42 @@ export default async function () {
6987
buildTarget['configurations']['production'] = { aot: true };
7088
});
7189

72-
// Test `import()` style lazy load.
73-
await replaceLoadChildren(`() => import('./lazy/lazy.module').then(m => m.LazyModule)`);
74-
await ng('e2e');
75-
await ng('e2e', '--prod');
76-
7790
// Test string import with factory shims.
7891
await replaceLoadChildren(`'./lazy/lazy.module#LazyModule'`);
7992
await replaceInFile('tsconfig.app.json', `"allowEmptyCodegenFiles": false`,
8093
`"allowEmptyCodegenFiles": true`);
81-
await expectToFail(() => ng('e2e')); // Currently broken.
82-
await ng('e2e', '--prod');
94+
if (ivyProject) {
95+
// Ivy should not support the string syntax.
96+
await expectToFail(() => ng('e2e'));
97+
await expectToFail(() => ng('e2e', '--prod'));
98+
} else {
99+
// View engine should support the string syntax.
100+
await ng('e2e');
101+
await ng('e2e', '--prod');
102+
}
83103

84104
// Test string import without factory shims.
85105
await replaceLoadChildren(`'./lazy/lazy.module#LazyModule'`);
86106
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.
107+
`"allowEmptyCodegenFiles": false`);
108+
if (ivyProject) {
109+
// Ivy should not support the string syntax.
110+
await expectToFail(() => ng('e2e'));
111+
await expectToFail(() => ng('e2e', '--prod'));
112+
} else {
113+
// View engine should support the string syntax.
114+
await ng('e2e');
115+
await ng('e2e', '--prod');
116+
}
117+
118+
// Test `import()` style lazy load.
119+
await updateJsonFile('angular.json', json => {
120+
// Add the experimental flag to import factories in View Engine.
121+
const buildTarget = json['projects'][projectName]['architect']['build'];
122+
buildTarget['options']['experimentalImportFactories'] = true;
123+
});
124+
// Both Ivy and View Engine should support it.
125+
await replaceLoadChildren(`() => import('./lazy/lazy.module').then(m => m.LazyModule)`);
126+
await ng('e2e');
127+
await ng('e2e', '--prod');
90128
}

0 commit comments

Comments
 (0)