From a29f9f3ab832e9d1e501a693524e77ac361bf122 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Fri, 19 Aug 2016 13:49:36 -0700 Subject: [PATCH] refactor(core/testing): remove deprecated TestComponentBuilder BREAKING CHANGE: deprecated TestComponentBuilder was removed, please use TestBed instead --- .../@angular/compiler/core_private_testing.ts | 3 - .../testing/test_component_builder.ts | 125 --------------- .../@angular/core/private_export_testing.ts | 4 - .../core/testing/test_component_builder.ts | 144 ------------------ .../@angular/core/testing/testing_internal.ts | 3 +- .../platform-browser-dynamic/testing.ts | 5 +- 6 files changed, 3 insertions(+), 281 deletions(-) delete mode 100644 modules/@angular/compiler/testing/test_component_builder.ts delete mode 100644 modules/@angular/core/testing/test_component_builder.ts diff --git a/modules/@angular/compiler/core_private_testing.ts b/modules/@angular/compiler/core_private_testing.ts index 113a24f315..75fa5a1b6c 100644 --- a/modules/@angular/compiler/core_private_testing.ts +++ b/modules/@angular/compiler/core_private_testing.ts @@ -13,6 +13,3 @@ export var TestingCompiler: typeof t.TestingCompiler = r.TestingCompiler; export type TestingCompilerFactory = t.TestingCompilerFactory; export var TestingCompilerFactory: typeof t.TestingCompilerFactory = r.TestingCompilerFactory; - -export type TestComponentBuilder = t.TestComponentBuilder; -export var TestComponentBuilder: typeof t.TestComponentBuilder = r.TestComponentBuilder; diff --git a/modules/@angular/compiler/testing/test_component_builder.ts b/modules/@angular/compiler/testing/test_component_builder.ts deleted file mode 100644 index 62bdb2edf0..0000000000 --- a/modules/@angular/compiler/testing/test_component_builder.ts +++ /dev/null @@ -1,125 +0,0 @@ -/** - * @license - * Copyright Google Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -import {AnimationEntryMetadata, Compiler, ComponentFactory, Inject, Injectable, Injector, NgZone, Type} from '@angular/core'; -import {ComponentFixture, ComponentFixtureNoNgZone, TestBed} from '@angular/core/testing'; - -import {ViewMetadata} from '../core_private'; -import {TestComponentBuilder} from '../core_private_testing'; -// export {ViewMetadata} from '../core_private'; - -import {DirectiveResolver} from '../index'; -import {MapWrapper} from '../src/facade/collection'; -import {isPresent} from '../src/facade/lang'; - - - -/** - * A TestComponentBuilder that allows overriding based on the compiler. - * - * @deprecated Use `TestBed.configureTestModule` / `TestBed.override...` / `TestBed.createComponent` - * instead. -*/ -@Injectable() -export class OverridingTestComponentBuilder extends TestComponentBuilder { - /** @internal */ - private _bindingsOverrides = new Map, any[]>(); - /** @internal */ - private _directiveOverrides = new Map, Map, Type>>(); - /** @internal */ - private _templateOverrides = new Map, string>(); - /** @internal */ - private _animationOverrides = new Map, AnimationEntryMetadata[]>(); - /** @internal */ - private _viewBindingsOverrides = new Map, any[]>(); - /** @internal */ - private _viewOverrides = new Map, ViewMetadata>(); - - constructor(@Inject(TestBed) injector: Injector) { super(injector); } - - /** @internal */ - _clone(): OverridingTestComponentBuilder { - let clone = new OverridingTestComponentBuilder(this._injector); - clone._viewOverrides = MapWrapper.clone(this._viewOverrides); - clone._directiveOverrides = MapWrapper.clone(this._directiveOverrides); - clone._templateOverrides = MapWrapper.clone(this._templateOverrides); - clone._bindingsOverrides = MapWrapper.clone(this._bindingsOverrides); - clone._viewBindingsOverrides = MapWrapper.clone(this._viewBindingsOverrides); - return clone; - } - - overrideTemplate(componentType: Type, template: string): OverridingTestComponentBuilder { - let clone = this._clone(); - clone._templateOverrides.set(componentType, template); - return clone; - } - - overrideAnimations(componentType: Type, animations: AnimationEntryMetadata[]): - TestComponentBuilder { - var clone = this._clone(); - clone._animationOverrides.set(componentType, animations); - return clone; - } - - overrideView(componentType: Type, view: ViewMetadata): OverridingTestComponentBuilder { - let clone = this._clone(); - clone._viewOverrides.set(componentType, view); - return clone; - } - - overrideDirective(componentType: Type, from: Type, to: Type): - OverridingTestComponentBuilder { - let clone = this._clone(); - let overridesForComponent = clone._directiveOverrides.get(componentType); - if (!isPresent(overridesForComponent)) { - clone._directiveOverrides.set(componentType, new Map, Type>()); - overridesForComponent = clone._directiveOverrides.get(componentType); - } - overridesForComponent.set(from, to); - return clone; - } - - overrideProviders(type: Type, providers: any[]): OverridingTestComponentBuilder { - let clone = this._clone(); - clone._bindingsOverrides.set(type, providers); - return clone; - } - - overrideViewProviders(type: Type, providers: any[]): OverridingTestComponentBuilder { - let clone = this._clone(); - clone._viewBindingsOverrides.set(type, providers); - return clone; - } - - createAsync(rootComponentType: Type): Promise> { - this._applyMetadataOverrides(); - return super.createAsync(rootComponentType); - } - - createSync(rootComponentType: Type): ComponentFixture { - this._applyMetadataOverrides(); - return super.createSync(rootComponentType); - } - - private _applyMetadataOverrides() { - let mockDirectiveResolver = this._injector.get(DirectiveResolver); - this._viewOverrides.forEach((view, type) => { mockDirectiveResolver.setView(type, view); }); - this._templateOverrides.forEach( - (template, type) => mockDirectiveResolver.setInlineTemplate(type, template)); - this._animationOverrides.forEach( - (animationsEntry, type) => mockDirectiveResolver.setAnimations(type, animationsEntry)); - this._directiveOverrides.forEach((overrides, component) => { - overrides.forEach( - (to, from) => { mockDirectiveResolver.overrideViewDirective(component, from, to); }); - }); - this._bindingsOverrides.forEach( - (bindings, type) => mockDirectiveResolver.setProvidersOverride(type, bindings)); - this._viewBindingsOverrides.forEach( - (bindings, type) => mockDirectiveResolver.setViewProvidersOverride(type, bindings)); - } -} diff --git a/modules/@angular/core/private_export_testing.ts b/modules/@angular/core/private_export_testing.ts index 14d3442609..574e8fd57c 100644 --- a/modules/@angular/core/private_export_testing.ts +++ b/modules/@angular/core/private_export_testing.ts @@ -7,19 +7,15 @@ */ import * as test_compiler from './testing/test_compiler'; -import * as test_component_builder from './testing/test_component_builder'; export declare namespace __core_private_testing_types__ { export type TestingCompiler = test_compiler.TestingCompiler; export var TestingCompiler: typeof test_compiler.TestingCompiler; export type TestingCompilerFactory = test_compiler.TestingCompilerFactory; export var TestingCompilerFactory: typeof test_compiler.TestingCompilerFactory; - export type TestComponentBuilder = test_component_builder.TestComponentBuilder; - export var TestComponentBuilder: typeof test_component_builder.TestComponentBuilder; } export var __core_private_testing__ = { TestingCompiler: test_compiler.TestingCompiler, TestingCompilerFactory: test_compiler.TestingCompilerFactory, - TestComponentBuilder: test_component_builder.TestComponentBuilder, }; diff --git a/modules/@angular/core/testing/test_component_builder.ts b/modules/@angular/core/testing/test_component_builder.ts deleted file mode 100644 index c38e335a5f..0000000000 --- a/modules/@angular/core/testing/test_component_builder.ts +++ /dev/null @@ -1,144 +0,0 @@ -/** - * @license - * Copyright Google Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -import {AnimationEntryMetadata, Compiler, ComponentFactory, Injectable, Injector, NgZone, OpaqueToken} from '../index'; -import {isPresent} from '../src/facade/lang'; -import {ViewMetadata} from '../src/metadata/view'; -import {Type} from '../src/type'; - -import {ComponentFixture} from './component_fixture'; -import {tick} from './fake_async'; -import {ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, TestComponentRenderer} from './test_bed'; - -var _nextRootElementId = 0; - -/** - * Builds a ComponentFixture for use in component level tests. - * - * @deprecated Use `TestBed.configureTestModule` / `TestBed.override...` / `TestBed.createComponent` - * instead. - */ -@Injectable() -export class TestComponentBuilder { - constructor(protected _injector: Injector) {} - - /** - * Overrides only the html of a {@link ComponentMetadata}. - * All the other properties of the component's {@link ViewMetadata} are preserved. - */ - overrideTemplate(componentType: Type, template: string): TestComponentBuilder { - throw new Error( - 'overrideTemplate is not supported in this implementation of TestComponentBuilder.'); - } - - /** - * Overrides a component's {@link ViewMetadata}. - */ - overrideView(componentType: Type, view: ViewMetadata): TestComponentBuilder { - throw new Error( - 'overrideView is not supported in this implementation of TestComponentBuilder.'); - } - - /** - * Overrides the directives from the component {@link ViewMetadata}. - */ - overrideDirective(componentType: Type, from: Type, to: Type): - TestComponentBuilder { - throw new Error( - 'overrideDirective is not supported in this implementation of TestComponentBuilder.'); - } - - /** - * Overrides one or more injectables configured via `providers` metadata property of a directive - * or - * component. - * Very useful when certain providers need to be mocked out. - * - * The providers specified via this method are appended to the existing `providers` causing the - * duplicated providers to - * be overridden. - */ - overrideProviders(type: Type, providers: any[]): TestComponentBuilder { - throw new Error( - 'overrideProviders is not supported in this implementation of TestComponentBuilder.'); - } - - /** - * Overrides one or more injectables configured via `providers` metadata property of a directive - * or - * component. - * Very useful when certain providers need to be mocked out. - * - * The providers specified via this method are appended to the existing `providers` causing the - * duplicated providers to - * be overridden. - */ - overrideViewProviders(type: Type, providers: any[]): TestComponentBuilder { - throw new Error( - 'overrideViewProviders is not supported in this implementation of TestComponentBuilder.'); - } - - overrideAnimations(componentType: Type, animations: AnimationEntryMetadata[]): - TestComponentBuilder { - throw new Error( - 'overrideAnimations is not supported in this implementation of TestComponentBuilder.'); - } - - protected createFromFactory(ngZone: NgZone, componentFactory: ComponentFactory): - ComponentFixture { - let rootElId = `root${_nextRootElementId++}`; - var testComponentRenderer: TestComponentRenderer = this._injector.get(TestComponentRenderer); - testComponentRenderer.insertRootElement(rootElId); - - var componentRef = componentFactory.create(this._injector, [], `#${rootElId}`); - let autoDetect: boolean = this._injector.get(ComponentFixtureAutoDetect, false); - return new ComponentFixture(componentRef, ngZone, autoDetect); - } - - /** - * Builds and returns a ComponentFixture. - */ - createAsync(rootComponentType: Type): Promise> { - let noNgZone = this._injector.get(ComponentFixtureNoNgZone, false); - let ngZone: NgZone = noNgZone ? null : this._injector.get(NgZone, null); - let compiler: Compiler = this._injector.get(Compiler); - - let initComponent = () => { - let promise: Promise> = - compiler.compileComponentAsync(rootComponentType); - return promise.then(componentFactory => this.createFromFactory(ngZone, componentFactory)); - }; - - return ngZone == null ? initComponent() : ngZone.run(initComponent); - } - - createFakeAsync(rootComponentType: Type): ComponentFixture { - let result: any /** TODO #9100 */; - let error: any /** TODO #9100 */; - - this.createAsync(rootComponentType) - .then((_result) => { result = _result; }, (_error) => { error = _error; }); - tick(); - if (isPresent(error)) { - throw error; - } - return result; - } - - createSync(rootComponentType: Type): ComponentFixture { - let noNgZone = this._injector.get(ComponentFixtureNoNgZone, false); - let ngZone: NgZone = noNgZone ? null : this._injector.get(NgZone, null); - let compiler: Compiler = this._injector.get(Compiler); - - let initComponent = () => { - return this.createFromFactory(ngZone, compiler.compileComponentSync(rootComponentType)); - }; - - return ngZone == null ? initComponent() : ngZone.run(initComponent); - } -} diff --git a/modules/@angular/core/testing/testing_internal.ts b/modules/@angular/core/testing/testing_internal.ts index e3b5609cd4..e64593e65f 100644 --- a/modules/@angular/core/testing/testing_internal.ts +++ b/modules/@angular/core/testing/testing_internal.ts @@ -7,7 +7,7 @@ */ import {StringMapWrapper} from '../src/facade/collection'; -import {Math, global, isFunction, isPromise} from '../src/facade/lang'; +import {Math, global, isPromise} from '../src/facade/lang'; import {AsyncTestCompleter} from './async_test_completer'; import {TestBed, getTestBed, inject} from './test_bed'; @@ -17,7 +17,6 @@ export {MockAnimationPlayer} from './mock_animation_player'; export {inject} from './test_bed'; export * from './logger'; export * from './ng_zone_mock'; -export * from './test_component_builder'; export var proxy: ClassDecorator = (t: any /** TODO #9100 */) => t; diff --git a/modules/@angular/platform-browser-dynamic/testing.ts b/modules/@angular/platform-browser-dynamic/testing.ts index a3fdd73c3f..6412984aa0 100644 --- a/modules/@angular/platform-browser-dynamic/testing.ts +++ b/modules/@angular/platform-browser-dynamic/testing.ts @@ -6,9 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ -import {OverridingTestComponentBuilder, platformCoreDynamicTesting} from '@angular/compiler/testing'; +import {platformCoreDynamicTesting} from '@angular/compiler/testing'; import {NgModule, PlatformRef, createPlatformFactory} from '@angular/core'; -import {TestComponentRenderer, __core_private_testing__ as r, __core_private_testing_types__ as t} from '@angular/core/testing'; +import {TestComponentRenderer} from '@angular/core/testing'; import {BrowserTestingModule} from '@angular/platform-browser/testing'; import {INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS} from './src/platform_providers'; @@ -31,7 +31,6 @@ export const platformBrowserDynamicTesting = createPlatformFactory( @NgModule({ exports: [BrowserTestingModule], providers: [ - {provide: r.TestComponentBuilder, useClass: OverridingTestComponentBuilder}, {provide: TestComponentRenderer, useClass: DOMTestComponentRenderer}, ] })