From 0614797d84a9ff804dea8e474f4252958ab8089d Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Thu, 3 Dec 2015 13:31:11 -0800 Subject: [PATCH] refactor(test_injector): Provide separate methods for creating test injector with and without runtime compiler. BREAKING CHANGE: `createTestInjector()` does not more include the runtime compiler. Use `createTestInjectorWithRuntimeCompiler()` instead. Closes #5583 --- modules/angular2/src/testing/test_injector.ts | 15 ++++++++++++++- modules/angular2/src/testing/testing.ts | 11 ++++++++--- .../angular2/src/testing/testing_internal.dart | 2 +- modules/angular2/src/testing/testing_internal.ts | 14 +++++++++----- .../test/web_workers/shared/message_bus_spec.ts | 2 +- .../shared/service_message_broker_spec.ts | 2 +- .../web_workers/worker/event_dispatcher_spec.ts | 2 +- .../worker/renderer_integration_spec.ts | 4 ++-- .../test/web_workers/worker/xhr_impl_spec.ts | 2 +- .../angular2_testing/lib/angular2_testing.dart | 2 +- 10 files changed, 39 insertions(+), 17 deletions(-) diff --git a/modules/angular2/src/testing/test_injector.ts b/modules/angular2/src/testing/test_injector.ts index efc5c8499b..a622a0e254 100644 --- a/modules/angular2/src/testing/test_injector.ts +++ b/modules/angular2/src/testing/test_injector.ts @@ -57,6 +57,7 @@ import {COMPILER_PROVIDERS} from 'angular2/src/compiler/compiler'; import {DomRenderer_} from "angular2/src/platform/dom/dom_renderer"; import {DynamicComponentLoader_} from "angular2/src/core/linker/dynamic_component_loader"; import {AppViewManager_} from "angular2/src/core/linker/view_manager"; +import {APPLICATION_COMMON_PROVIDERS} from 'angular2/src/core/application_common_providers'; /** * Returns the root injector providers. @@ -87,7 +88,7 @@ function _getAppBindings() { } return [ - COMPILER_PROVIDERS, + APPLICATION_COMMON_PROVIDERS, provide(ChangeDetectorGenConfig, {useValue: new ChangeDetectorGenConfig(true, false, true)}), provide(DOCUMENT, {useValue: appDoc}), provide(DomRenderer, {useClass: DomRenderer_}), @@ -120,11 +121,23 @@ function _getAppBindings() { ]; } +function _runtimeCompilerBindings() { + return [ + provide(XHR, {useClass: DOM.getXHR()}), + COMPILER_PROVIDERS, + ]; +} + export function createTestInjector(providers: Array): Injector { var rootInjector = Injector.resolveAndCreate(_getRootProviders()); return rootInjector.resolveAndCreateChild(ListWrapper.concat(_getAppBindings(), providers)); } +export function createTestInjectorWithRuntimeCompiler( + providers: Array): Injector { + return createTestInjector(ListWrapper.concat(_runtimeCompilerBindings(), providers)); +} + /** * Allows injecting dependencies in `beforeEach()` and `it()`. When using with the * `angular2/testing` library, the test function will be run within a zone and will diff --git a/modules/angular2/src/testing/testing.ts b/modules/angular2/src/testing/testing.ts index f6cacfb5f1..5c108abb51 100644 --- a/modules/angular2/src/testing/testing.ts +++ b/modules/angular2/src/testing/testing.ts @@ -6,7 +6,12 @@ import {global} from 'angular2/src/facade/lang'; import {ListWrapper} from 'angular2/src/facade/collection'; import {bind} from 'angular2/src/core/di'; -import {createTestInjector, FunctionWithParamTokens, inject, injectAsync} from './test_injector'; +import { + createTestInjectorWithRuntimeCompiler, + FunctionWithParamTokens, + inject, + injectAsync +} from './test_injector'; export {inject, injectAsync} from './test_injector'; @@ -150,7 +155,7 @@ function _it(jsmFn: Function, name: string, testFn: FunctionWithParamTokens | An if (testFn instanceof FunctionWithParamTokens) { jsmFn(name, (done) => { if (!injector) { - injector = createTestInjector(testProviders); + injector = createTestInjectorWithRuntimeCompiler(testProviders); } var returnedTestValue = runInTestZone(() => testFn.execute(injector), done, done.fail); @@ -179,7 +184,7 @@ export function beforeEach(fn: FunctionWithParamTokens | AnyTestFn): void { jsmBeforeEach((done) => { if (!injector) { - injector = createTestInjector(testProviders); + injector = createTestInjectorWithRuntimeCompiler(testProviders); } runInTestZone(() => fn.execute(injector), done, done.fail); diff --git a/modules/angular2/src/testing/testing_internal.dart b/modules/angular2/src/testing/testing_internal.dart index 333c1a6557..0bc0f6d5a2 100644 --- a/modules/angular2/src/testing/testing_internal.dart +++ b/modules/angular2/src/testing/testing_internal.dart @@ -63,7 +63,7 @@ void testSetup() { gns.beforeEach(() { _isCurrentTestAsync = false; _testBindings.add(completerBinding); - _injector = createTestInjector(_testBindings); + _injector = createTestInjectorWithRuntimeCompiler(_testBindings); }, priority: 1); } diff --git a/modules/angular2/src/testing/testing_internal.ts b/modules/angular2/src/testing/testing_internal.ts index 602ee75f30..f8c8985668 100644 --- a/modules/angular2/src/testing/testing_internal.ts +++ b/modules/angular2/src/testing/testing_internal.ts @@ -5,7 +5,11 @@ import {NgZoneZone} from 'angular2/src/core/zone/ng_zone'; import {provide} from 'angular2/src/core/di'; -import {createTestInjector, FunctionWithParamTokens, inject} from './test_injector'; +import { + createTestInjectorWithRuntimeCompiler, + FunctionWithParamTokens, + inject +} from './test_injector'; import {browserDetection} from './utils'; export {inject} from './test_injector'; @@ -143,7 +147,7 @@ function _it(jsmFn: Function, name: string, testFn: FunctionWithParamTokens | An } }); - var injector = createTestInjector([...testProviders, completerProvider]); + var injector = createTestInjectorWithRuntimeCompiler([...testProviders, completerProvider]); runner.run(injector); inIt = true; @@ -152,7 +156,7 @@ function _it(jsmFn: Function, name: string, testFn: FunctionWithParamTokens | An }, timeOut); } else { jsmFn(name, () => { - var injector = createTestInjector(testProviders); + var injector = createTestInjectorWithRuntimeCompiler(testProviders); runner.run(injector); testFn.execute(injector); }, timeOut); @@ -163,13 +167,13 @@ function _it(jsmFn: Function, name: string, testFn: FunctionWithParamTokens | An if ((testFn).length === 0) { jsmFn(name, () => { - var injector = createTestInjector(testProviders); + var injector = createTestInjectorWithRuntimeCompiler(testProviders); runner.run(injector); (testFn)(); }, timeOut); } else { jsmFn(name, (done) => { - var injector = createTestInjector(testProviders); + var injector = createTestInjectorWithRuntimeCompiler(testProviders); runner.run(injector); (testFn)(done); }, timeOut); diff --git a/modules/angular2/test/web_workers/shared/message_bus_spec.ts b/modules/angular2/test/web_workers/shared/message_bus_spec.ts index 545aef2620..e4fcc2ade0 100644 --- a/modules/angular2/test/web_workers/shared/message_bus_spec.ts +++ b/modules/angular2/test/web_workers/shared/message_bus_spec.ts @@ -5,7 +5,7 @@ import { it, expect, beforeEach, - createTestInjector, + createTestInjectorWithRuntimeCompiler, beforeEachProviders, SpyObject, proxy diff --git a/modules/angular2/test/web_workers/shared/service_message_broker_spec.ts b/modules/angular2/test/web_workers/shared/service_message_broker_spec.ts index 49100a99f6..9b0b148221 100644 --- a/modules/angular2/test/web_workers/shared/service_message_broker_spec.ts +++ b/modules/angular2/test/web_workers/shared/service_message_broker_spec.ts @@ -5,7 +5,7 @@ import { it, expect, beforeEach, - createTestInjector, + createTestInjectorWithRuntimeCompiler, beforeEachProviders, SpyObject, proxy diff --git a/modules/angular2/test/web_workers/worker/event_dispatcher_spec.ts b/modules/angular2/test/web_workers/worker/event_dispatcher_spec.ts index 40e66fac1c..5efa1ea811 100644 --- a/modules/angular2/test/web_workers/worker/event_dispatcher_spec.ts +++ b/modules/angular2/test/web_workers/worker/event_dispatcher_spec.ts @@ -5,7 +5,7 @@ import { it, expect, beforeEach, - createTestInjector, + createTestInjectorWithRuntimeCompiler, beforeEachProviders, SpyObject, proxy diff --git a/modules/angular2/test/web_workers/worker/renderer_integration_spec.ts b/modules/angular2/test/web_workers/worker/renderer_integration_spec.ts index b48a12a745..65d3b9ab83 100644 --- a/modules/angular2/test/web_workers/worker/renderer_integration_spec.ts +++ b/modules/angular2/test/web_workers/worker/renderer_integration_spec.ts @@ -7,7 +7,7 @@ import { iit, expect, beforeEach, - createTestInjector, + createTestInjectorWithRuntimeCompiler, beforeEachProviders, TestComponentBuilder } from "angular2/testing_internal"; @@ -101,7 +101,7 @@ export function main() { beforeEachProviders(() => { var uiRenderProtoViewStore = new RenderProtoViewRefStore(false); uiRenderViewStore = new RenderViewWithFragmentsStore(false); - uiInjector = createTestInjector([ + uiInjector = createTestInjectorWithRuntimeCompiler([ provide(RenderProtoViewRefStore, {useValue: uiRenderProtoViewStore}), provide(RenderViewWithFragmentsStore, {useValue: uiRenderViewStore}), provide(DomRenderer, {useClass: DomRenderer_}), diff --git a/modules/angular2/test/web_workers/worker/xhr_impl_spec.ts b/modules/angular2/test/web_workers/worker/xhr_impl_spec.ts index 5058f256ab..83fe0f9828 100644 --- a/modules/angular2/test/web_workers/worker/xhr_impl_spec.ts +++ b/modules/angular2/test/web_workers/worker/xhr_impl_spec.ts @@ -5,7 +5,7 @@ import { it, expect, beforeEach, - createTestInjector, + createTestInjectorWithRuntimeCompiler, beforeEachProviders } from 'angular2/testing_internal'; import {SpyMessageBroker} from './spies'; diff --git a/modules_dart/angular2_testing/lib/angular2_testing.dart b/modules_dart/angular2_testing/lib/angular2_testing.dart index e5c1a87902..60d1302dd3 100644 --- a/modules_dart/angular2_testing/lib/angular2_testing.dart +++ b/modules_dart/angular2_testing/lib/angular2_testing.dart @@ -73,7 +73,7 @@ dynamic _runInjectableFunction(Function fn) { } if (_currentInjector == null) { - _currentInjector = createTestInjector(_currentTestProviders); + _currentInjector = createTestInjectorWithRuntimeCompiler(_currentTestProviders); } var injectFn = new FunctionWithParamTokens(tokens, fn, false); return injectFn.execute(_currentInjector);