fix(browser): platform code cleanup

This commit is contained in:
Victor Berchet
2016-05-20 16:11:49 -07:00
parent 9634e8d14a
commit 75e6dfb9ab
39 changed files with 626 additions and 821 deletions

View File

@ -1,40 +1,40 @@
import {
beforeEach,
afterEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xdescribe,
xit
} from '@angular/core/testing/testing_internal';
import {Log} from '@angular/core/testing';
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
import {stringify} from '../../src/facade/lang';
import {BROWSER_PLATFORM_PROVIDERS} from '@angular/platform-browser';
import {BROWSER_APP_PROVIDERS} from '@angular/platform-browser';
import {bootstrap} from '@angular/platform-browser';
import {ApplicationRef} from '@angular/core/src/application_ref';
import {Console} from '@angular/core/src/console';
import {Component, Directive, OnDestroy} from '@angular/core';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {DOCUMENT} from '@angular/platform-browser/src/dom/dom_tokens';
import {PromiseWrapper} from '../../src/facade/async';
AsyncTestCompleter
} from "@angular/core/testing/testing_internal";
import {Log} from "@angular/core/testing";
import {stringify} from "../../src/facade/lang";
import {
BROWSER_PLATFORM_PROVIDERS,
BROWSER_APP_PROVIDERS,
BROWSER_APP_COMPILER_PROVIDERS,
bootstrap
} from "@angular/platform-browser";
import {ApplicationRef, disposePlatform} from "@angular/core/src/application_ref";
import {Console} from "@angular/core/src/console";
import {
Component,
Directive,
OnDestroy,
provide,
Inject,
PLATFORM_INITIALIZER,
APP_INITIALIZER,
coreLoadAndBootstrap,
createPlatform,
ReflectiveInjector
} from '@angular/core';
import {disposePlatform} from '@angular/core/src/application_ref';
import {ExceptionHandler, BaseException} from '@angular/core';
import {Testability, TestabilityRegistry} from '@angular/core/src/testability/testability';
import {ComponentRef} from '@angular/core/src/linker/component_factory';
ReflectiveInjector,
ExceptionHandler
} from "@angular/core";
import {getDOM} from "@angular/platform-browser/src/dom/dom_adapter";
import {DOCUMENT} from "@angular/platform-browser/src/dom/dom_tokens";
import {PromiseWrapper} from "../../src/facade/async";
import {Testability, TestabilityRegistry} from "@angular/core/src/testability/testability";
import {ComponentRef} from "@angular/core/src/linker/component_factory";
@Component({selector: 'hello-app', template: '{{greeting}} world!'})
class HelloRootCmp {
@ -211,7 +211,7 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
var platform = createPlatform(ReflectiveInjector.resolveAndCreate(BROWSER_PLATFORM_PROVIDERS));
var app =
ReflectiveInjector.resolveAndCreate([BROWSER_APP_PROVIDERS, testProviders],
ReflectiveInjector.resolveAndCreate([BROWSER_APP_PROVIDERS, BROWSER_APP_COMPILER_PROVIDERS, testProviders],
platform.injector)
.get(ApplicationRef);
coreLoadAndBootstrap(HelloRootCmp, app.injector)

View File

@ -13,13 +13,11 @@ import {
import {
fakeAsync,
async,
flushMicrotasks,
withProviders,
Log,
tick,
} from '@angular/core/testing';
import {TestComponentBuilder} from '@angular/compiler/testing';
import {Injectable, bind, Component, ViewMetadata} from '@angular/core';
import {Injectable, provide, Component, ViewMetadata} from '@angular/core';
import {NgIf} from '@angular/common';
import {PromiseWrapper} from '../../http/src/facade/promise';
@ -136,7 +134,7 @@ export function main() {
describe('using the test injector with the inject helper', () => {
describe('setting up Providers', () => {
beforeEachProviders(() => [bind(FancyService).toValue(new FancyService())]);
beforeEachProviders(() => [provide(FancyService, {useValue: new FancyService()})]);
it('should use set up providers',
inject([FancyService], (service) => { expect(service.value).toEqual('real value'); }));
@ -187,12 +185,12 @@ export function main() {
describe('per test providers', () => {
it('should allow per test providers',
withProviders(() => [bind(FancyService).toValue(new FancyService())])
withProviders(() => [provide(FancyService, {useValue: new FancyService()})])
.inject([FancyService],
(service) => { expect(service.value).toEqual('real value'); }));
it('should return value from inject', () => {
let retval = withProviders(() => [bind(FancyService).toValue(new FancyService())])
let retval = withProviders(() => [provide(FancyService, {useValue: new FancyService()})])
.inject([FancyService], (service) => {
expect(service.value).toEqual('real value');
return 10;
@ -233,7 +231,7 @@ export function main() {
};
var restoreJasmineBeforeEach =
() => { jasmine.getEnv().beforeEach = originalJasmineBeforeEach; }
() => { jasmine.getEnv().beforeEach = originalJasmineBeforeEach; };
it('should fail when an asynchronous error is thrown', (done) => {
var itPromise = patchJasmineIt();
@ -267,7 +265,7 @@ export function main() {
});
describe('using beforeEachProviders', () => {
beforeEachProviders(() => [bind(FancyService).toValue(new FancyService())]);
beforeEachProviders(() => [provide(FancyService, {useValue: new FancyService()})]);
beforeEach(
inject([FancyService], (service) => { expect(service.value).toEqual('real value'); }));
@ -277,7 +275,7 @@ export function main() {
it('should fail when the injector has already been used', () => {
patchJasmineBeforeEach();
expect(() => {
beforeEachProviders(() => [bind(FancyService).toValue(new FancyService())]);
beforeEachProviders(() => [provide(FancyService, {useValue: new FancyService()})]);
})
.toThrowError('beforeEachProviders was called after the injector had been used ' +
'in a beforeEach or it block. This invalidates the test injector');
@ -366,7 +364,7 @@ export function main() {
it('should override a provider',
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
tcb.overrideProviders(TestProvidersComp, [bind(FancyService).toClass(MockFancyService)])
tcb.overrideProviders(TestProvidersComp, [provide(FancyService, {useClass: MockFancyService})])
.createAsync(TestProvidersComp)
.then((componentFixture) => {
componentFixture.detectChanges();
@ -380,7 +378,7 @@ export function main() {
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
tcb.overrideViewProviders(TestViewProvidersComp,
[bind(FancyService).toClass(MockFancyService)])
[provide(FancyService, {useClass: MockFancyService})])
.createAsync(TestViewProvidersComp)
.then((componentFixture) => {
componentFixture.detectChanges();

View File

@ -13,23 +13,18 @@ import {TestInjector} from '@angular/core/testing';
import {TestComponentBuilder} from '@angular/compiler/testing';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {
bind,
provide,
Provider,
Injector,
ViewMetadata,
Component,
Injectable,
ElementRef,
ComponentRef
} from '@angular/core';
import {NgIf} from '@angular/common';
import {WebWorkerRootRenderer} from '@angular/platform-browser/src/web_workers/worker/renderer';
import {
ClientMessageBrokerFactory,
ClientMessageBrokerFactory_,
UiArguments,
FnArg
ClientMessageBrokerFactory_
} from '@angular/platform-browser/src/web_workers/shared/client_message_broker';
import {Serializer} from '@angular/platform-browser/src/web_workers/shared/serializer';
import {RootRenderer} from '@angular/core/src/render/api';
@ -39,14 +34,13 @@ import {RenderStore} from '@angular/platform-browser/src/web_workers/shared/rend
import {MessageBasedRenderer} from '@angular/platform-browser/src/web_workers/ui/renderer';
import {createPairedMessageBuses, PairedMessageBuses} from '../shared/web_worker_test_util';
import {
ServiceMessageBrokerFactory,
ServiceMessageBrokerFactory_
} from '@angular/platform-browser/src/web_workers/shared/service_message_broker';
import {CompilerConfig} from '@angular/compiler';
import {dispatchEvent} from '../../../../platform-browser/testing/browser_util';
import {
TEST_BROWSER_STATIC_PLATFORM_PROVIDERS,
TEST_BROWSER_STATIC_APPLICATION_PROVIDERS
TEST_BROWSER_PLATFORM_PROVIDERS,
TEST_BROWSER_APPLICATION_PROVIDERS
} from '@angular/platform-browser/testing';
export function main() {
@ -88,8 +82,8 @@ export function main() {
beforeEachProviders(() => {
uiRenderStore = new RenderStore();
var testUiInjector = new TestInjector();
testUiInjector.platformProviders = TEST_BROWSER_STATIC_PLATFORM_PROVIDERS;
testUiInjector.applicationProviders = TEST_BROWSER_STATIC_APPLICATION_PROVIDERS;
testUiInjector.platformProviders = TEST_BROWSER_PLATFORM_PROVIDERS;
testUiInjector.applicationProviders = TEST_BROWSER_APPLICATION_PROVIDERS;
testUiInjector.addProviders([
Serializer,
provide(RenderStore, {useValue: uiRenderStore}),

View File

@ -11,7 +11,6 @@ import {
} from '@angular/core/testing/testing_internal';
import {XHRImpl} from '../../src/xhr/xhr_impl';
import {PromiseWrapper} from '../../src/facade/async';
import {IS_DART} from '../../src/facade/lang';
export function main() {
describe('XHRImpl', () => {
@ -23,8 +22,7 @@ export function main() {
// will be relative to here, so url200 should look like
// static_assets/200.html.
// We currently have no way of detecting this.
var urlBase = IS_DART ? '' : '/base/modules/@angular/';
var url200 = urlBase + 'platform-browser/test/browser/static_assets/200.html';
var url200 = '/base/modules/@angular/platform-browser/test/browser/static_assets/200.html';
var url404 = '/bad/path/404.html';
beforeEach(() => { xhr = new XHRImpl(); });