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
This commit is contained in:
parent
0823622202
commit
a6c8cc3215
|
@ -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', () => {
|
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,
|
// 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
|
// which indirectly imports a LibModule (via another NgModule in the middle). The test is
|
||||||
|
|
Loading…
Reference in New Issue