Skip to content

Commit 430e759

Browse files
filipesilvavikerman
authored andcommitted
test: re-enable lazy route error tests for Ivy
1 parent 45155dc commit 430e759

File tree

1 file changed

+54
-44
lines changed

1 file changed

+54
-44
lines changed

packages/angular_devkit/build_angular/test/browser/lazy-module_spec_large.ts

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ describe('Browser Builder lazy modules', () => {
4545
);
4646
}
4747

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+
4856
const cases: [string, Record<string, string>][] = [
4957
['string', lazyModuleStringImport],
5058
['function', lazyModuleFnImport],
@@ -63,50 +71,6 @@ describe('Browser Builder lazy modules', () => {
6371
expect('lazy-lazy-module.js' in files).toBe(true);
6472
});
6573

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-
11074
it('supports lazy bundle for lazy routes with AOT', async () => {
11175
host.writeMultipleFiles(lazyModuleFiles);
11276
host.writeMultipleFiles(imports);
@@ -124,6 +88,52 @@ describe('Browser Builder lazy modules', () => {
12488
});
12589
}
12690

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+
127137
it(`supports lazy bundle for import() calls`, async () => {
128138
host.writeMultipleFiles({
129139
'src/lazy-module.ts': 'export const value = 42;',

0 commit comments

Comments
 (0)