revert: fix(ivy): Only restore registered modules if user compiles modules with TestBed (#32944) (#33663)

This commit reverts 63256b5.

PR Close #33663
This commit is contained in:
Andrew Scott
2019-11-08 10:16:40 -08:00
committed by Kara Erickson
parent 4988094e7d
commit f8e9c1e6f1
5 changed files with 23 additions and 47 deletions

View File

@ -17,7 +17,7 @@ import {expect} from '@angular/platform-browser/testing/src/matchers';
import {modifiedInIvy, obsoleteInIvy, onlyInIvy} from '@angular/private/testing';
import {InternalNgModuleRef, NgModuleFactory} from '../../src/linker/ng_module_factory';
import {clearRegisteredModuleState} from '../../src/linker/ng_module_factory_registration';
import {clearModuleRegistry} from '../../src/linker/ng_module_factory_registration';
import {stringify} from '../../src/util/stringify';
class Engine {}
@ -294,7 +294,11 @@ function declareTests(config?: {useJit: boolean}) {
describe('id', () => {
const token = 'myid';
afterEach(() => clearRegisteredModuleState());
// Ivy TestBed clears module registry in resetTestingModule so this afterEach is not needed
// for Ivy
if (!ivyEnabled) {
afterEach(() => clearModuleRegistry());
}
it('should register loaded modules', () => {
@NgModule({id: token})

View File

@ -6,9 +6,13 @@
* found in the LICENSE file at https://angular.io/license
*/
<<<<<<< HEAD
import {Compiler, Component, Directive, ErrorHandler, Inject, Injectable, InjectionToken, Injector, Input, ModuleWithProviders, NgModule, Optional, Pipe, getModuleFactory, ɵsetClassMetadata as setClassMetadata, ɵɵdefineComponent as defineComponent, ɵɵdefineNgModule as defineNgModule, ɵɵtext as text} from '@angular/core';
import {registerModuleFactory} from '@angular/core/src/linker/ng_module_factory_registration';
import {NgModuleFactory} from '@angular/core/src/render3';
=======
import {Compiler, Component, Directive, ErrorHandler, Inject, Injectable, InjectionToken, Input, ModuleWithProviders, NgModule, Optional, Pipe, getModuleFactory, ɵsetClassMetadata as setClassMetadata, ɵɵdefineComponent as defineComponent, ɵɵdefineNgModule as defineNgModule, ɵɵtext as text} from '@angular/core';
>>>>>>> parent of 63256b511a... fix(ivy): Only restore registered modules if user compiles modules with TestBed (#32944)
import {TestBed, getTestBed} from '@angular/core/testing/src/test_bed';
import {By} from '@angular/platform-browser';
import {expect} from '@angular/platform-browser/testing/src/matchers';
@ -909,30 +913,15 @@ describe('TestBed', () => {
});
onlyInIvy('Ivy module registration happens when NgModuleFactory is created')
.describe('cleans up registered modules - ', () => {
it('removes modules registered with TestBed', async() => {
@NgModule({id: 'my_module'})
class MyModule {
}
.it('cleans up registered modules', async() => {
@NgModule({id: 'my_module'})
class MyModule {
}
expect(() => getModuleFactory('my_module')).toThrowError();
await TestBed.inject(Compiler).compileModuleAsync(MyModule);
expect(() => getModuleFactory('my_module')).not.toThrowError();
TestBed.resetTestingModule();
expect(() => getModuleFactory('my_module')).toThrowError();
});
it('does not remove modules registered outside TestBed (i.e., side effect registration in ngfactory files)',
() => {
@NgModule({id: 'auto_module'})
class AutoModule {
}
expect(() => getModuleFactory('auto_module')).toThrowError();
registerModuleFactory('auto_module', new NgModuleFactory(AutoModule));
expect(() => getModuleFactory('auto_module')).not.toThrowError();
TestBed.resetTestingModule();
expect(() => getModuleFactory('auto_module')).not.toThrowError();
});
expect(() => getModuleFactory('my_module')).toThrowError();
await TestBed.inject(Compiler).compileModuleAsync(MyModule);
expect(() => getModuleFactory('my_module')).not.toThrowError();
TestBed.resetTestingModule();
expect(() => getModuleFactory('my_module')).toThrowError();
});
});