Skip to content

Commit ec903cf

Browse files
committed
test(@angular-devkit/build-angular): add template error recovery unit-test for application builder
A unit-test for the application builder has been added to that tests the rebuilds are triggered when a template error has been introduced in a rebuild. The test also confirms that rebuilds continue to function after the error has been corrected. (cherry picked from commit d8edbfb)
1 parent d28ba8a commit ec903cf

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

packages/angular_devkit/build_angular/src/builders/application/tests/behavior/rebuild-errors_spec.ts

+63
Original file line numberDiff line numberDiff line change
@@ -313,5 +313,68 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
313313

314314
expect(buildCount).toBe(3);
315315
});
316+
317+
it('recovers from component template error', async () => {
318+
harness.useTarget('build', {
319+
...BASE_OPTIONS,
320+
watch: true,
321+
});
322+
323+
const builderAbort = new AbortController();
324+
const buildCount = await harness
325+
.execute({ outputLogsOnFailure: true, signal: builderAbort.signal })
326+
.pipe(
327+
timeout(BUILD_TIMEOUT),
328+
concatMap(async ({ result, logs }, index) => {
329+
switch (index) {
330+
case 0:
331+
// Missing ending `>` on the div will cause an error
332+
await harness.appendToFile('src/app/app.component.html', '<div>Hello, world!</div');
333+
334+
break;
335+
case 1:
336+
expect(logs).toContain(
337+
jasmine.objectContaining<logging.LogEntry>({
338+
message: jasmine.stringMatching('Unexpected character "EOF"'),
339+
}),
340+
);
341+
342+
await harness.appendToFile('src/app/app.component.html', '>');
343+
344+
break;
345+
case 2:
346+
expect(logs).not.toContain(
347+
jasmine.objectContaining<logging.LogEntry>({
348+
message: jasmine.stringMatching('Unexpected character "EOF"'),
349+
}),
350+
);
351+
352+
harness.expectFile('dist/browser/main.js').content.toContain('Hello, world!');
353+
354+
// Make an additional valid change to ensure that rebuilds still trigger
355+
await harness.appendToFile('src/app/app.component.html', '<div>Guten Tag</div>');
356+
357+
break;
358+
case 3:
359+
expect(logs).not.toContain(
360+
jasmine.objectContaining<logging.LogEntry>({
361+
message: jasmine.stringMatching('invalid-css-content'),
362+
}),
363+
);
364+
365+
harness.expectFile('dist/browser/main.js').content.toContain('Hello, world!');
366+
harness.expectFile('dist/browser/main.js').content.toContain('Guten Tag');
367+
368+
// Test complete - abort watch mode
369+
builderAbort?.abort();
370+
break;
371+
}
372+
}),
373+
count(),
374+
)
375+
.toPromise();
376+
377+
expect(buildCount).toBe(4);
378+
});
316379
});
317380
});

0 commit comments

Comments
 (0)