fix(ivy): TestBed rewrite to avoid unnecessary recompilations (#29483)
Prior to this change, Ivy version of TestBed was not designed to support the logic to avoid recompilations - most of the Components/Directives/Pipes were recompiled for each test, even if there were no overrides defined for a given Type. Additional checks to avoid recompilation were introduced in one of the previous commits (0244a2433e
), but there were still some corner cases that required attention. In order to support the necessary logic better, Ivy TestBed was rewritten/refactored. Main results of this rewrite are:
* no recompilation for Components/Directives/Pipes without overrides
* the logic to restore state between tests (isolate tests) was improved
* transitive scopes calculation no longer performs recompilation (it works with compiled defs)
As a result of these changes we see reduction in memory consumption (3.5-4x improvement) and pefromance increase (4-4.5x improvement).
PR Close #29483
This commit is contained in:

committed by
Miško Hevery

parent
fea2a0f2ac
commit
309ffe7e16
@ -777,18 +777,28 @@ class CompWithUrlTemplate {
|
||||
describe('setting up the compiler', () => {
|
||||
|
||||
describe('providers', () => {
|
||||
beforeEach(() => {
|
||||
const resourceLoaderGet = jasmine.createSpy('resourceLoaderGet')
|
||||
.and.returnValue(Promise.resolve('Hello world!'));
|
||||
TestBed.configureTestingModule({declarations: [CompWithUrlTemplate]});
|
||||
TestBed.configureCompiler(
|
||||
{providers: [{provide: ResourceLoader, useValue: {get: resourceLoaderGet}}]});
|
||||
});
|
||||
|
||||
it('should use set up providers', fakeAsync(() => {
|
||||
// Keeping this component inside the test is needed to make sure it's not resolved
|
||||
// prior to this test, thus having ngComponentDef and a reference in resource
|
||||
// resolution queue. This is done to check external resoution logic in isolation by
|
||||
// configuring TestBed with the necessary ResourceLoader instance.
|
||||
@Component({
|
||||
selector: 'comp',
|
||||
templateUrl: '/base/angular/packages/platform-browser/test/static_assets/test.html'
|
||||
})
|
||||
class InternalCompWithUrlTemplate {
|
||||
}
|
||||
|
||||
const resourceLoaderGet = jasmine.createSpy('resourceLoaderGet')
|
||||
.and.returnValue(Promise.resolve('Hello world!'));
|
||||
TestBed.configureTestingModule({declarations: [InternalCompWithUrlTemplate]});
|
||||
TestBed.configureCompiler(
|
||||
{providers: [{provide: ResourceLoader, useValue: {get: resourceLoaderGet}}]});
|
||||
|
||||
TestBed.compileComponents();
|
||||
tick();
|
||||
const compFixture = TestBed.createComponent(CompWithUrlTemplate);
|
||||
const compFixture = TestBed.createComponent(InternalCompWithUrlTemplate);
|
||||
expect(compFixture.nativeElement).toHaveText('Hello world!');
|
||||
}));
|
||||
});
|
||||
|
Reference in New Issue
Block a user