feat(ivy): avoid unnecessary recompilations in TestBed (#29294)

Prior to this change, we always recompile all Components/Directives/Pipes even if they were AOT-compiled and had no overrides. This is causing problems in case we try to recompile a Component with "templateUrl" or "styleUrls" (which were already resolved in case of AOT) and generally this unnecessary work that TestBed was doing is not required. This commit adds extra logic to check whether a Component/Directive/Pipe already have compiled NG def (like ngComponentDef) and whether there are no overrides present - in this case recompilation is skipped. Recompilation is also skipped in case a Component/Directive has only Provider overrides - in this situation providers resolver function is patched to reflect overrides. Provider overrides are very common in g3, thus this code path ensures no full recompilation.

PR Close #29294
This commit is contained in:
Andrew Kushnir
2019-03-11 10:35:25 -07:00
committed by Matias Niemelä
parent 86aba1e8f3
commit 0244a2433e
11 changed files with 207 additions and 60 deletions

View File

@ -900,17 +900,24 @@ class CompWithUrlTemplate {
() => {
const itPromise = patchJasmineIt();
@Component({
selector: 'comp',
templateUrl: '/base/angular/packages/platform-browser/test/static_assets/test.html'
})
class InlineCompWithUrlTemplate {
}
expect(
() =>
it('should fail', withModule(
{declarations: [CompWithUrlTemplate]},
() => TestBed.createComponent(CompWithUrlTemplate))))
() => it(
'should fail', withModule(
{declarations: [InlineCompWithUrlTemplate]},
() => TestBed.createComponent(InlineCompWithUrlTemplate))))
.toThrowError(
ivyEnabled ?
`Component 'CompWithUrlTemplate' is not resolved:
`Component 'InlineCompWithUrlTemplate' is not resolved:
- templateUrl: /base/angular/packages/platform-browser/test/static_assets/test.html
Did you run and wait for 'resolveComponentResources()'?` :
`This test module uses the component ${stringify(CompWithUrlTemplate)} which is using a "templateUrl" or "styleUrls", but they were never compiled. ` +
`This test module uses the component ${stringify(InlineCompWithUrlTemplate)} which is using a "templateUrl" or "styleUrls", but they were never compiled. ` +
`Please call "TestBed.compileComponents" before your test.`);
restoreJasmineIt();