feat(core): allow to pass in aot summaries also to TestBed.configureTestingModule
Also adds caching for summaries. Closes #19817.
This commit is contained in:

committed by
Victor Berchet

parent
b489259a34
commit
05d96dc507
@ -45,6 +45,7 @@ export type TestModuleMetadata = {
|
||||
declarations?: any[],
|
||||
imports?: any[],
|
||||
schemas?: Array<SchemaMetadata|any[]>,
|
||||
aotSummaries?: () => any[],
|
||||
};
|
||||
|
||||
/**
|
||||
@ -205,7 +206,8 @@ export class TestBed implements Injector {
|
||||
private _schemas: Array<SchemaMetadata|any[]> = [];
|
||||
private _activeFixtures: ComponentFixture<any>[] = [];
|
||||
|
||||
private _aotSummaries: () => any[] = () => [];
|
||||
private _testEnvAotSummaries: () => any[] = () => [];
|
||||
private _aotSummaries: Array<() => any[]> = [];
|
||||
|
||||
platform: PlatformRef = null !;
|
||||
|
||||
@ -232,7 +234,7 @@ export class TestBed implements Injector {
|
||||
this.platform = platform;
|
||||
this.ngModule = ngModule;
|
||||
if (aotSummaries) {
|
||||
this._aotSummaries = aotSummaries;
|
||||
this._testEnvAotSummaries = aotSummaries;
|
||||
}
|
||||
}
|
||||
|
||||
@ -245,11 +247,12 @@ export class TestBed implements Injector {
|
||||
this.resetTestingModule();
|
||||
this.platform = null !;
|
||||
this.ngModule = null !;
|
||||
this._aotSummaries = () => [];
|
||||
this._testEnvAotSummaries = () => [];
|
||||
}
|
||||
|
||||
resetTestingModule() {
|
||||
clearProviderOverrides();
|
||||
this._aotSummaries = [];
|
||||
this._compiler = null !;
|
||||
this._moduleOverrides = [];
|
||||
this._componentOverrides = [];
|
||||
@ -293,6 +296,9 @@ export class TestBed implements Injector {
|
||||
if (moduleDef.schemas) {
|
||||
this._schemas.push(...moduleDef.schemas);
|
||||
}
|
||||
if (moduleDef.aotSummaries) {
|
||||
this._aotSummaries.push(moduleDef.aotSummaries);
|
||||
}
|
||||
}
|
||||
|
||||
compileComponents(): Promise<any> {
|
||||
@ -350,7 +356,9 @@ export class TestBed implements Injector {
|
||||
const compilerFactory: TestingCompilerFactory =
|
||||
this.platform.injector.get(TestingCompilerFactory);
|
||||
this._compiler = compilerFactory.createTestingCompiler(this._compilerOptions);
|
||||
this._compiler.loadAotSummaries(this._aotSummaries);
|
||||
for (const summary of [this._testEnvAotSummaries, ...this._aotSummaries]) {
|
||||
this._compiler.loadAotSummaries(summary);
|
||||
}
|
||||
this._moduleOverrides.forEach((entry) => this._compiler.overrideModule(entry[0], entry[1]));
|
||||
this._componentOverrides.forEach(
|
||||
(entry) => this._compiler.overrideComponent(entry[0], entry[1]));
|
||||
|
Reference in New Issue
Block a user