From a6c8cc3215b28987aeb10243ffef67d0f5f5acf2 Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Wed, 25 Nov 2020 15:02:44 -0800 Subject: [PATCH] test(compiler-cli): validate broken external template incrementality (#39923) Previously, if a component had an external template with a hard error, the compiler would "forget" the link between that component and its NgModule. Additionally, the NgModule would be marked as being in error, because the template issue would prevent the compiler from registering the component class as a component, so from the NgModule it would look like a declaration of a non-directive/pipe class. As a combined result, the next incremental step could fix the template error, but would not refresh diagnostics for the NgModule, leading to an incrementality issue. The various facets of this problem were fixed in prior commits. This commit adds a test verifying the above case works now as expected. PR Close #39923 --- .../test/ngtsc/incremental_error_spec.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/compiler-cli/test/ngtsc/incremental_error_spec.ts b/packages/compiler-cli/test/ngtsc/incremental_error_spec.ts index ef3e020e2c..8e99294340 100644 --- a/packages/compiler-cli/test/ngtsc/incremental_error_spec.ts +++ b/packages/compiler-cli/test/ngtsc/incremental_error_spec.ts @@ -288,6 +288,38 @@ runInEachFileSystem(() => { ]); }); + it('should recover from an error in an external template', () => { + env.write('mod.ts', ` + import {NgModule} from '@angular/core'; + import {Cmp} from './cmp'; + + @NgModule({ + declarations: [Cmp], + }) + export class Mod {} + `); + env.write('cmp.html', '{{ error = "true" }} '); + env.write('cmp.ts', ` + import {Component} from '@angular/core'; + + @Component({ + templateUrl: './cmp.html', + selector: 'some-cmp', + }) + export class Cmp { + error = 'false'; + } + `); + + // Diagnostics should show for the broken component template. + expect(env.driveDiagnostics().length).toBeGreaterThan(0); + + env.write('cmp.html', '{{ error }} '); + + // There should be no diagnostics. + env.driveMain(); + }); + it('should recover from an error even across multiple NgModules', () => { // This test is a variation on the above. Two components (CmpA and CmpB) exist in an NgModule, // which indirectly imports a LibModule (via another NgModule in the middle). The test is