From f1b0547f0a1ed110337ccd47eb29477bc6dc1e69 Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Fri, 8 Nov 2019 10:18:46 -0800 Subject: [PATCH] revert: fix(ivy): R3TestBed should clean up registered modules after each test (#32872) (#33663) This commit reverts 475e36a. PR Close #33663 --- .../linker/ng_module_factory_registration.ts | 2 +- .../test/linker/ng_module_integration_spec.ts | 8 ++----- packages/core/test/test_bed_spec.ts | 21 +------------------ packages/core/testing/src/r3_test_bed.ts | 2 -- 4 files changed, 4 insertions(+), 29 deletions(-) diff --git a/packages/core/src/linker/ng_module_factory_registration.ts b/packages/core/src/linker/ng_module_factory_registration.ts index 92ec31e420..3008d8434a 100644 --- a/packages/core/src/linker/ng_module_factory_registration.ts +++ b/packages/core/src/linker/ng_module_factory_registration.ts @@ -56,7 +56,7 @@ export function registerNgModuleType(ngModuleType: NgModuleType) { } } -export function clearModuleRegistry(): void { +export function clearModulesForTest(): void { modules.clear(); } diff --git a/packages/core/test/linker/ng_module_integration_spec.ts b/packages/core/test/linker/ng_module_integration_spec.ts index 28b79a9107..152f42e68c 100644 --- a/packages/core/test/linker/ng_module_integration_spec.ts +++ b/packages/core/test/linker/ng_module_integration_spec.ts @@ -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 {clearModuleRegistry} from '../../src/linker/ng_module_factory_registration'; +import {clearModulesForTest} from '../../src/linker/ng_module_factory_registration'; import {stringify} from '../../src/util/stringify'; class Engine {} @@ -294,11 +294,7 @@ function declareTests(config?: {useJit: boolean}) { describe('id', () => { const token = 'myid'; - // Ivy TestBed clears module registry in resetTestingModule so this afterEach is not needed - // for Ivy - if (!ivyEnabled) { - afterEach(() => clearModuleRegistry()); - } + afterEach(() => clearModulesForTest()); it('should register loaded modules', () => { @NgModule({id: token}) diff --git a/packages/core/test/test_bed_spec.ts b/packages/core/test/test_bed_spec.ts index eccb23344d..a282deaed4 100644 --- a/packages/core/test/test_bed_spec.ts +++ b/packages/core/test/test_bed_spec.ts @@ -6,13 +6,7 @@ * 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 {Compiler, Component, Directive, ErrorHandler, Inject, Injectable, InjectionToken, Injector, Input, ModuleWithProviders, NgModule, Optional, Pipe, ɵsetClassMetadata as setClassMetadata, ɵɵdefineComponent as defineComponent, ɵɵdefineNgModule as defineNgModule, ɵɵtext as text} from '@angular/core'; 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'; @@ -911,17 +905,4 @@ describe('TestBed', () => { .toEqual(originalResolver); }); }); - - onlyInIvy('Ivy module registration happens when NgModuleFactory is created') - .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(); - }); }); diff --git a/packages/core/testing/src/r3_test_bed.ts b/packages/core/testing/src/r3_test_bed.ts index 5ea00a5188..3f4b285e57 100644 --- a/packages/core/testing/src/r3_test_bed.ts +++ b/packages/core/testing/src/r3_test_bed.ts @@ -35,7 +35,6 @@ import {MetadataOverride} from './metadata_override'; import {TestBed} from './test_bed'; import {ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, TestBedStatic, TestComponentRenderer, TestModuleMetadata} from './test_bed_common'; import {R3TestBedCompiler} from './r3_test_bed_compiler'; -import {clearModuleRegistry} from '../../src/linker/ng_module_factory_registration'; let _nextRootElementId = 0; @@ -229,7 +228,6 @@ export class TestBedRender3 implements TestBed { } resetTestingModule(): void { - clearModuleRegistry(); this.checkGlobalCompilationFinished(); resetCompiledComponents(); if (this._compiler !== null) {