fix(ivy): Only restore registered modules if user compiles modules with TestBed (#32944)
There are a couple scenarios that are problematic and need special handling: 1. A user has a custom implementation of lazy-loaded modules, sets some provider overrides, then compiles the module so it can be loaded. In a follow-up test, the user sets different overrides for the module and then compiles. This is problematic because we need to be sure the module registered in the first test is not used, so we need to clear it out of the modules list in `ng_module_factory_registration`. 2. A user has a similar lazy-loaded module factory implementation but relies on the module being registered automatically. This can happen, for example, as a side effect of importing the ngfactory file. PR Close #32944
This commit is contained in:
@ -12,13 +12,14 @@ import {stringify} from '../util/stringify';
|
||||
|
||||
import {NgModuleFactory} from './ng_module_factory';
|
||||
|
||||
export type ModuleRegistrationMap = Map<string, NgModuleFactory<any>|NgModuleType>;
|
||||
|
||||
/**
|
||||
* Map of module-id to the corresponding NgModule.
|
||||
* - In pre Ivy we track NgModuleFactory,
|
||||
* - In post Ivy we track the NgModuleType
|
||||
*/
|
||||
const modules = new Map<string, NgModuleFactory<any>|NgModuleType>();
|
||||
let modules: ModuleRegistrationMap = new Map();
|
||||
|
||||
/**
|
||||
* Registers a loaded module. Should only be called from generated NgModuleFactory code.
|
||||
@ -54,10 +55,18 @@ export function registerNgModuleType(ngModuleType: NgModuleType) {
|
||||
}
|
||||
}
|
||||
|
||||
export function clearModuleRegistry(): void {
|
||||
export function clearRegisteredModuleState(): void {
|
||||
modules.clear();
|
||||
}
|
||||
|
||||
export function getRegisteredModulesState(): ModuleRegistrationMap {
|
||||
return new Map(modules);
|
||||
}
|
||||
|
||||
export function restoreRegisteredModulesState(moduleMap: ModuleRegistrationMap) {
|
||||
modules = new Map(moduleMap);
|
||||
}
|
||||
|
||||
export function getRegisteredNgModuleType(id: string) {
|
||||
return modules.get(id);
|
||||
}
|
||||
|
Reference in New Issue
Block a user