fix: split dynamic bits in platform-browser into platform-browser-dynamic
Previously these symbols were exposed via platform-browser-dynamic, then we merged then into platform-browser thinking that tools would know how to shake off the compiler and other dynamic bits not used with the offline compilation flow. This turned out to be wrong as both webpack and rollup don't have good enough tree-shaking capabilities to do this today. We think that in the future we'll be able to merge these two entry points into one, but we need to give tooling some time before we can do it. In the meantime the reintroduction of the -dynamic package point allows us to separate the compiler dependencies from the rest of the framework. This change undoes the previous breaking change that removed the platform-browser-dynamic package.
This commit is contained in:
@ -0,0 +1,4 @@
|
||||
import {__core_private__ as r, __core_private_types__ as t} from '@angular/core';
|
||||
|
||||
export var ReflectionCapabilities: typeof t.ReflectionCapabilities = r.ReflectionCapabilities;
|
||||
export var reflector: typeof t.reflector = r.reflector;
|
@ -1,10 +1,148 @@
|
||||
import {BROWSER_APP_COMPILER_PROVIDERS, BROWSER_APP_PROVIDERS} from '@angular/platform-browser';
|
||||
import {COMMON_DIRECTIVES, COMMON_PIPES} from '@angular/common';
|
||||
import {COMPILER_PROVIDERS, CompilerConfig, XHR} from '@angular/compiler';
|
||||
import {ApplicationRef, ComponentRef, ReflectiveInjector, Type, coreLoadAndBootstrap} from '@angular/core';
|
||||
import {BROWSER_APP_PROVIDERS, WORKER_APP_APPLICATION_PROVIDERS, WORKER_RENDER_APPLICATION_PROVIDERS, WORKER_SCRIPT, browserPlatform, workerAppPlatform, workerRenderPlatform} from '@angular/platform-browser';
|
||||
|
||||
export {CACHED_TEMPLATE_PROVIDER, bootstrap} from '@angular/platform-browser';
|
||||
import {ReflectionCapabilities, reflector} from './core_private';
|
||||
import {PromiseWrapper} from './src/facade/async';
|
||||
import {isPresent} from './src/facade/lang';
|
||||
import {CachedXHR} from './src/xhr/xhr_cache';
|
||||
import {XHRImpl} from './src/xhr/xhr_impl';
|
||||
|
||||
|
||||
/* @deprecated the platform-browser-dynamic module is deprecated. */
|
||||
export const BROWSER_APP_DYNAMIC_PROVIDERS: Array<any /*Type | Provider | any[]*/> =
|
||||
[BROWSER_APP_PROVIDERS, BROWSER_APP_COMPILER_PROVIDERS];
|
||||
export const BROWSER_APP_COMPILER_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
|
||||
COMPILER_PROVIDERS,
|
||||
{
|
||||
provide: CompilerConfig,
|
||||
useValue:
|
||||
new CompilerConfig({platformDirectives: COMMON_DIRECTIVES, platformPipes: COMMON_PIPES})
|
||||
},
|
||||
{provide: XHR, useClass: XHRImpl},
|
||||
];
|
||||
|
||||
console.log(`platform-browser-dynamic is deprecated, use platform-browser instead`);
|
||||
|
||||
export const CACHED_TEMPLATE_PROVIDER: Array<any /*Type | Provider | any[]*/> =
|
||||
[{provide: XHR, useClass: CachedXHR}];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Bootstrapping for Angular applications.
|
||||
*
|
||||
* You instantiate an Angular application by explicitly specifying a component to use
|
||||
* as the root component for your application via the `bootstrap()` method.
|
||||
*
|
||||
* ## Simple Example
|
||||
*
|
||||
* Assuming this `index.html`:
|
||||
*
|
||||
* ```html
|
||||
* <html>
|
||||
* <!-- load Angular script tags here. -->
|
||||
* <body>
|
||||
* <my-app>loading...</my-app>
|
||||
* </body>
|
||||
* </html>
|
||||
* ```
|
||||
*
|
||||
* An application is bootstrapped inside an existing browser DOM, typically `index.html`.
|
||||
* Unlike Angular 1, Angular 2 does not compile/process providers in `index.html`. This is
|
||||
* mainly for security reasons, as well as architectural changes in Angular 2. This means
|
||||
* that `index.html` can safely be processed using server-side technologies such as
|
||||
* providers. Bindings can thus use double-curly `{{ syntax }}` without collision from
|
||||
* Angular 2 component double-curly `{{ syntax }}`.
|
||||
*
|
||||
* We can use this script code:
|
||||
*
|
||||
* {@example core/ts/bootstrap/bootstrap.ts region='bootstrap'}
|
||||
*
|
||||
* When the app developer invokes `bootstrap()` with the root component `MyApp` as its
|
||||
* argument, Angular performs the following tasks:
|
||||
*
|
||||
* 1. It uses the component's `selector` property to locate the DOM element which needs
|
||||
* to be upgraded into the angular component.
|
||||
* 2. It creates a new child injector (from the platform injector). Optionally, you can
|
||||
* also override the injector configuration for an app by invoking `bootstrap` with the
|
||||
* `componentInjectableBindings` argument.
|
||||
* 3. It creates a new `Zone` and connects it to the angular application's change detection
|
||||
* domain instance.
|
||||
* 4. It creates an emulated or shadow DOM on the selected component's host element and loads the
|
||||
* template into it.
|
||||
* 5. It instantiates the specified component.
|
||||
* 6. Finally, Angular performs change detection to apply the initial data providers for the
|
||||
* application.
|
||||
*
|
||||
*
|
||||
* ## Bootstrapping Multiple Applications
|
||||
*
|
||||
* When working within a browser window, there are many singleton resources: cookies, title,
|
||||
* location, and others. Angular services that represent these resources must likewise be
|
||||
* shared across all Angular applications that occupy the same browser window. For this
|
||||
* reason, Angular creates exactly one global platform object which stores all shared
|
||||
* services, and each angular application injector has the platform injector as its parent.
|
||||
*
|
||||
* Each application has its own private injector as well. When there are multiple
|
||||
* applications on a page, Angular treats each application injector's services as private
|
||||
* to that application.
|
||||
*
|
||||
* ## API
|
||||
*
|
||||
* - `appComponentType`: The root component which should act as the application. This is
|
||||
* a reference to a `Type` which is annotated with `@Component(...)`.
|
||||
* - `customProviders`: An additional set of providers that can be added to the
|
||||
* app injector to override default injection behavior.
|
||||
*
|
||||
* Returns a `Promise` of {@link ComponentRef}.
|
||||
*/
|
||||
export function bootstrap(
|
||||
appComponentType: Type,
|
||||
customProviders?: Array<any /*Type | Provider | any[]*/>): Promise<ComponentRef<any>> {
|
||||
reflector.reflectionCapabilities = new ReflectionCapabilities();
|
||||
let providers = [
|
||||
BROWSER_APP_PROVIDERS, BROWSER_APP_COMPILER_PROVIDERS,
|
||||
isPresent(customProviders) ? customProviders : []
|
||||
];
|
||||
var appInjector = ReflectiveInjector.resolveAndCreate(providers, browserPlatform().injector);
|
||||
return coreLoadAndBootstrap(appComponentType, appInjector);
|
||||
}
|
||||
|
||||
|
||||
export function bootstrapRender(
|
||||
workerScriptUri: string,
|
||||
customProviders?: Array<any /*Type | Provider | any[]*/>): Promise<ApplicationRef> {
|
||||
var app = ReflectiveInjector.resolveAndCreate(
|
||||
[
|
||||
WORKER_RENDER_APPLICATION_PROVIDERS, BROWSER_APP_COMPILER_PROVIDERS,
|
||||
{provide: WORKER_SCRIPT, useValue: workerScriptUri},
|
||||
isPresent(customProviders) ? customProviders : []
|
||||
],
|
||||
workerRenderPlatform().injector);
|
||||
// Return a promise so that we keep the same semantics as Dart,
|
||||
// and we might want to wait for the app side to come up
|
||||
// in the future...
|
||||
return PromiseWrapper.resolve(app.get(ApplicationRef));
|
||||
}
|
||||
|
||||
|
||||
const WORKER_APP_COMPILER_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
|
||||
COMPILER_PROVIDERS,
|
||||
{
|
||||
provide: CompilerConfig,
|
||||
useValue:
|
||||
new CompilerConfig({platformDirectives: COMMON_DIRECTIVES, platformPipes: COMMON_PIPES})
|
||||
},
|
||||
{provide: XHR, useClass: XHRImpl},
|
||||
];
|
||||
|
||||
|
||||
export function bootstrapApp(
|
||||
appComponentType: Type,
|
||||
customProviders?: Array<any /*Type | Provider | any[]*/>): Promise<ComponentRef<any>> {
|
||||
var appInjector = ReflectiveInjector.resolveAndCreate(
|
||||
[
|
||||
WORKER_APP_APPLICATION_PROVIDERS, WORKER_APP_COMPILER_PROVIDERS,
|
||||
isPresent(customProviders) ? customProviders : []
|
||||
],
|
||||
workerAppPlatform().injector);
|
||||
return coreLoadAndBootstrap(appComponentType, appInjector);
|
||||
}
|
||||
|
@ -0,0 +1,3 @@
|
||||
import {__platform_browser_private__ as r, __platform_browser_private__ as t} from '@angular/platform-browser';
|
||||
|
||||
export var getDOM: typeof t.getDOM = r.getDOM;
|
1
modules/@angular/platform-browser-dynamic/src/facade
Symbolic link
1
modules/@angular/platform-browser-dynamic/src/facade
Symbolic link
@ -0,0 +1 @@
|
||||
../../facade/src
|
@ -0,0 +1,31 @@
|
||||
import {XHR} from '@angular/compiler';
|
||||
import {BaseException} from '../facade/exceptions';
|
||||
import {global} from '../facade/lang';
|
||||
import {PromiseWrapper} from '../facade/promise';
|
||||
|
||||
/**
|
||||
* An implementation of XHR that uses a template cache to avoid doing an actual
|
||||
* XHR.
|
||||
*
|
||||
* The template cache needs to be built and loaded into window.$templateCache
|
||||
* via a separate mechanism.
|
||||
*/
|
||||
export class CachedXHR extends XHR {
|
||||
private _cache: {[url: string]: string};
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this._cache = (<any>global).$templateCache;
|
||||
if (this._cache == null) {
|
||||
throw new BaseException('CachedXHR: Template cache was not found in $templateCache.');
|
||||
}
|
||||
}
|
||||
|
||||
get(url: string): Promise<string> {
|
||||
if (this._cache.hasOwnProperty(url)) {
|
||||
return PromiseWrapper.resolve(this._cache[url]);
|
||||
} else {
|
||||
return PromiseWrapper.reject('CachedXHR: Did not find cached template for ' + url, null);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
import {XHR} from '@angular/compiler';
|
||||
|
||||
import {isPresent} from '../facade/lang';
|
||||
import {PromiseCompleter, PromiseWrapper} from '../facade/promise';
|
||||
|
||||
export class XHRImpl extends XHR {
|
||||
get(url: string): Promise<string> {
|
||||
var completer: PromiseCompleter<string> = PromiseWrapper.completer();
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.responseType = 'text';
|
||||
|
||||
xhr.onload = function() {
|
||||
// responseText is the old-school way of retrieving response (supported by IE8 & 9)
|
||||
// response/responseType properties were introduced in XHR Level2 spec (supported by IE10)
|
||||
var response = isPresent(xhr.response) ? xhr.response : xhr.responseText;
|
||||
|
||||
// normalize IE9 bug (http://bugs.jquery.com/ticket/1450)
|
||||
var status = xhr.status === 1223 ? 204 : xhr.status;
|
||||
|
||||
// fix status code when it is 0 (0 status is undocumented).
|
||||
// Occurs when accessing file resources or on Android 4.1 stock browser
|
||||
// while retrieving files from application cache.
|
||||
if (status === 0) {
|
||||
status = response ? 200 : 0;
|
||||
}
|
||||
|
||||
if (200 <= status && status <= 300) {
|
||||
completer.resolve(response);
|
||||
} else {
|
||||
completer.reject(`Failed to load ${url}`, null);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function() { completer.reject(`Failed to load ${url}`, null); };
|
||||
|
||||
xhr.send();
|
||||
return completer.promise;
|
||||
}
|
||||
}
|
@ -0,0 +1,183 @@
|
||||
import {it, iit, xit, describe, ddescribe, xdescribe, expect, beforeEach, beforeEachProviders, inject,} from '@angular/core/testing';
|
||||
import {async, fakeAsync, flushMicrotasks, Log, tick,} from '@angular/core/testing';
|
||||
|
||||
import {ROUTER_FAKE_PROVIDERS} from '@angular/router/testing';
|
||||
import {ROUTER_DIRECTIVES, Routes, Route} from '@angular/router';
|
||||
|
||||
|
||||
import {Component, bind} from '@angular/core';
|
||||
import {PromiseWrapper} from '../src/facade/promise';
|
||||
import {XHR} from '@angular/compiler';
|
||||
import {XHRImpl} from '../src/xhr/xhr_impl';
|
||||
import {TestComponentBuilder} from '@angular/compiler/testing';
|
||||
|
||||
// Components for the tests.
|
||||
class FancyService {
|
||||
value: string = 'real value';
|
||||
getAsyncValue() { return Promise.resolve('async value'); }
|
||||
getTimeoutValue() {
|
||||
return new Promise((resolve, reject) => { setTimeout(() => {resolve('timeout value')}, 10); })
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'external-template-comp',
|
||||
templateUrl: '/base/modules/@angular/platform-browser/test/static_assets/test.html'
|
||||
})
|
||||
class ExternalTemplateComp {
|
||||
}
|
||||
|
||||
@Component({selector: 'bad-template-comp', templateUrl: 'non-existant.html'})
|
||||
class BadTemplateUrl {
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'test-router-cmp',
|
||||
template:
|
||||
`<a [routerLink]="['One']">one</a> <a [routerLink]="['Two']">two</a><router-outlet></router-outlet>`,
|
||||
directives: [ROUTER_DIRECTIVES]
|
||||
})
|
||||
@Routes([
|
||||
new Route({path: '/One', component: BadTemplateUrl}),
|
||||
new Route({path: '/Two', component: ExternalTemplateComp}),
|
||||
])
|
||||
class TestRouterComponent {
|
||||
}
|
||||
|
||||
// Tests for angular2/testing bundle specific to the browser environment.
|
||||
// For general tests, see test/testing/testing_public_spec.ts.
|
||||
export function main() {
|
||||
describe('test APIs for the browser', () => {
|
||||
describe('angular2 jasmine matchers', () => {
|
||||
describe('toHaveCssClass', () => {
|
||||
it('should assert that the CSS class is present', () => {
|
||||
var el = document.createElement('div');
|
||||
el.classList.add('matias');
|
||||
expect(el).toHaveCssClass('matias');
|
||||
});
|
||||
|
||||
it('should assert that the CSS class is not present', () => {
|
||||
var el = document.createElement('div');
|
||||
el.classList.add('matias');
|
||||
expect(el).not.toHaveCssClass('fatias');
|
||||
});
|
||||
});
|
||||
|
||||
describe('toHaveCssStyle', () => {
|
||||
it('should assert that the CSS style is present', () => {
|
||||
var el = document.createElement('div');
|
||||
expect(el).not.toHaveCssStyle('width');
|
||||
|
||||
el.style.setProperty('width', '100px');
|
||||
expect(el).toHaveCssStyle('width');
|
||||
});
|
||||
|
||||
it('should assert that the styles are matched against the element', () => {
|
||||
var el = document.createElement('div');
|
||||
expect(el).not.toHaveCssStyle({width: '100px', height: '555px'});
|
||||
|
||||
el.style.setProperty('width', '100px');
|
||||
expect(el).toHaveCssStyle({width: '100px'});
|
||||
expect(el).not.toHaveCssStyle({width: '100px', height: '555px'});
|
||||
|
||||
el.style.setProperty('height', '555px');
|
||||
expect(el).toHaveCssStyle({height: '555px'});
|
||||
expect(el).toHaveCssStyle({width: '100px', height: '555px'});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('using the async helper', () => {
|
||||
var actuallyDone: boolean;
|
||||
|
||||
beforeEach(() => { actuallyDone = false; });
|
||||
|
||||
afterEach(() => { expect(actuallyDone).toEqual(true); });
|
||||
|
||||
it('should run async tests with XHRs', async(() => {
|
||||
var xhr = new XHRImpl();
|
||||
xhr.get('/base/modules/@angular/platform-browser/test/static_assets/test.html')
|
||||
.then(() => { actuallyDone = true; });
|
||||
}),
|
||||
10000); // Long timeout here because this test makes an actual XHR.
|
||||
});
|
||||
|
||||
describe('using the test injector with the inject helper', () => {
|
||||
describe('setting up Providers', () => {
|
||||
beforeEachProviders(() => [{provide: FancyService, useValue: new FancyService()}]);
|
||||
|
||||
it('provides a real XHR instance',
|
||||
inject([XHR], (xhr: XHR) => { expect(xhr).toBeAnInstanceOf(XHRImpl); }));
|
||||
|
||||
it('should allow the use of fakeAsync',
|
||||
fakeAsync(inject([FancyService], (service: any /** TODO #9100 */) => {
|
||||
var value: any /** TODO #9100 */;
|
||||
service.getAsyncValue().then(function(val: any /** TODO #9100 */) { value = val; });
|
||||
tick();
|
||||
expect(value).toEqual('async value');
|
||||
})));
|
||||
});
|
||||
});
|
||||
|
||||
describe('errors', () => {
|
||||
var originalJasmineIt: any;
|
||||
|
||||
var patchJasmineIt = () => {
|
||||
var deferred = PromiseWrapper.completer();
|
||||
originalJasmineIt = jasmine.getEnv().it;
|
||||
jasmine.getEnv().it = (description: string, fn: any /** TODO #9100 */) => {
|
||||
var done = () => { deferred.resolve() };
|
||||
(<any>done).fail = (err: any /** TODO #9100 */) => { deferred.reject(err) };
|
||||
fn(done);
|
||||
return null;
|
||||
};
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
var restoreJasmineIt = () => { jasmine.getEnv().it = originalJasmineIt; };
|
||||
|
||||
it('should fail when an XHR fails', (done: any /** TODO #9100 */) => {
|
||||
var itPromise = patchJasmineIt();
|
||||
|
||||
it('should fail with an error from a promise',
|
||||
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
return tcb.createAsync(BadTemplateUrl);
|
||||
})));
|
||||
|
||||
itPromise.then(
|
||||
() => { done.fail('Expected test to fail, but it did not'); },
|
||||
(err) => {
|
||||
expect(err).toEqual('Uncaught (in promise): Failed to load non-existant.html');
|
||||
done();
|
||||
});
|
||||
restoreJasmineIt();
|
||||
}, 10000);
|
||||
});
|
||||
|
||||
describe('test component builder', function() {
|
||||
it('should allow an external templateUrl',
|
||||
async(inject(
|
||||
[TestComponentBuilder],
|
||||
(tcb: TestComponentBuilder) => {
|
||||
|
||||
tcb.createAsync(ExternalTemplateComp).then((componentFixture) => {
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.debugElement.nativeElement)
|
||||
.toHaveText('from external template\n');
|
||||
});
|
||||
})),
|
||||
10000); // Long timeout here because this test makes an actual XHR, and is slow on Edge.
|
||||
});
|
||||
});
|
||||
|
||||
describe('apps with router components', () => {
|
||||
beforeEachProviders(() => [ROUTER_FAKE_PROVIDERS]);
|
||||
|
||||
it('should build without a problem',
|
||||
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
tcb.createAsync(TestRouterComponent).then((fixture) => {
|
||||
expect(fixture.nativeElement).toHaveText('one two');
|
||||
});
|
||||
})));
|
||||
});
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
export function setTemplateCache(cache: any /** TODO #9100 */): void {
|
||||
(<any>window).$templateCache = cache;
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
import {UrlResolver, XHR} from '@angular/compiler';
|
||||
import {Component, provide} from '@angular/core';
|
||||
import {beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
|
||||
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
|
||||
import {expect} from '@angular/platform-browser/testing';
|
||||
|
||||
import {fakeAsync, flushMicrotasks, Log, tick,} from '@angular/core/testing';
|
||||
import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing';
|
||||
import {BaseException} from '../../src/facade/exceptions';
|
||||
import {CachedXHR} from '../../src/xhr/xhr_cache';
|
||||
import {setTemplateCache} from './xhr_cache_setter';
|
||||
|
||||
export function main() {
|
||||
describe('CachedXHR', () => {
|
||||
var xhr: CachedXHR;
|
||||
|
||||
function createCachedXHR(): CachedXHR {
|
||||
setTemplateCache({'test.html': '<div>Hello</div>'});
|
||||
return new CachedXHR();
|
||||
}
|
||||
beforeEachProviders(() => [{provide: UrlResolver, useClass: TestUrlResolver}, {
|
||||
provide: XHR,
|
||||
useFactory: createCachedXHR
|
||||
}]);
|
||||
|
||||
it('should throw exception if $templateCache is not found', () => {
|
||||
setTemplateCache(null);
|
||||
expect(() => {
|
||||
xhr = new CachedXHR();
|
||||
}).toThrowErrorWith('CachedXHR: Template cache was not found in $templateCache.');
|
||||
});
|
||||
|
||||
it('should resolve the Promise with the cached file content on success',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
setTemplateCache({'test.html': '<div>Hello</div>'});
|
||||
xhr = new CachedXHR();
|
||||
xhr.get('test.html').then((text) => {
|
||||
expect(text).toEqual('<div>Hello</div>');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should reject the Promise on failure',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
xhr = new CachedXHR();
|
||||
xhr.get('unknown.html')
|
||||
.then((text) => { throw new BaseException('Not expected to succeed.'); })
|
||||
.catch((error) => { async.done(); });
|
||||
}));
|
||||
|
||||
it('should allow fakeAsync Tests to load components with templateUrl synchronously',
|
||||
fakeAsync(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
let fixture = tcb.createFakeAsync(TestComponent);
|
||||
|
||||
// This should initialize the fixture.
|
||||
tick();
|
||||
|
||||
expect(fixture.debugElement.children[0].nativeElement).toHaveText('Hello');
|
||||
})));
|
||||
});
|
||||
}
|
||||
|
||||
@Component({selector: 'test-cmp', templateUrl: 'test.html'})
|
||||
class TestComponent {
|
||||
}
|
||||
|
||||
class TestUrlResolver extends UrlResolver {
|
||||
resolve(baseUrl: string, url: string): string {
|
||||
// Don't use baseUrl to get the same URL as templateUrl.
|
||||
// This is to remove any difference between Dart and TS tests.
|
||||
return url;
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
import {AsyncTestCompleter, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
|
||||
|
||||
import {PromiseWrapper} from '../../src/facade/async';
|
||||
import {XHRImpl} from '../../src/xhr/xhr_impl';
|
||||
|
||||
export function main() {
|
||||
describe('XHRImpl', () => {
|
||||
var xhr: XHRImpl;
|
||||
|
||||
// TODO(juliemr): This file currently won't work with dart unit tests run using
|
||||
// exclusive it or describe (iit or ddescribe). This is because when
|
||||
// pub run test is executed against this specific file the relative paths
|
||||
// will be relative to here, so url200 should look like
|
||||
// static_assets/200.html.
|
||||
// We currently have no way of detecting this.
|
||||
var url200 = '/base/modules/@angular/platform-browser/test/browser/static_assets/200.html';
|
||||
var url404 = '/bad/path/404.html';
|
||||
|
||||
beforeEach(() => { xhr = new XHRImpl(); });
|
||||
|
||||
it('should resolve the Promise with the file content on success',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
xhr.get(url200).then((text) => {
|
||||
expect(text.trim()).toEqual('<p>hey</p>');
|
||||
async.done();
|
||||
});
|
||||
}), 10000);
|
||||
|
||||
it('should reject the Promise on failure',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
PromiseWrapper.catchError(xhr.get(url404), (e) => {
|
||||
expect(e).toEqual(`Failed to load ${url404}`);
|
||||
async.done();
|
||||
return null;
|
||||
});
|
||||
}), 10000);
|
||||
});
|
||||
}
|
@ -1,3 +1,25 @@
|
||||
export * from '@angular/platform-browser/testing';
|
||||
import {DirectiveResolver, ViewResolver} from '@angular/compiler';
|
||||
import {MockDirectiveResolver, MockViewResolver, TestComponentBuilder, TestComponentRenderer} from '@angular/compiler/testing';
|
||||
import {TEST_BROWSER_APPLICATION_PROVIDERS, TEST_BROWSER_PLATFORM_PROVIDERS} from '@angular/platform-browser/testing';
|
||||
|
||||
console.log(`platform-browser-dynamic/testing is deprecated, use platform-browser/testing instead`);
|
||||
import {BROWSER_APP_COMPILER_PROVIDERS} from './index';
|
||||
import {DOMTestComponentRenderer} from './testing/dom_test_component_renderer';
|
||||
|
||||
/**
|
||||
* Default platform providers for testing.
|
||||
*/
|
||||
export const TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS: Array<any /*Type | Provider | any[]*/> =
|
||||
[TEST_BROWSER_PLATFORM_PROVIDERS];
|
||||
|
||||
/**
|
||||
* Default application providers for testing.
|
||||
*/
|
||||
export const TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
|
||||
TEST_BROWSER_APPLICATION_PROVIDERS, BROWSER_APP_COMPILER_PROVIDERS,
|
||||
[
|
||||
{provide: DirectiveResolver, useClass: MockDirectiveResolver},
|
||||
{provide: ViewResolver, useClass: MockViewResolver},
|
||||
TestComponentBuilder,
|
||||
{provide: TestComponentRenderer, useClass: DOMTestComponentRenderer},
|
||||
]
|
||||
];
|
||||
|
@ -0,0 +1,27 @@
|
||||
import {TestComponentRenderer} from '@angular/compiler/testing';
|
||||
import {Inject, Injectable} from '@angular/core';
|
||||
import {DOCUMENT} from '@angular/platform-browser';
|
||||
import {el} from '@angular/platform-browser/testing';
|
||||
|
||||
import {getDOM} from '../platform_browser_private';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A DOM based implementation of the TestComponentRenderer.
|
||||
*/
|
||||
@Injectable()
|
||||
export class DOMTestComponentRenderer extends TestComponentRenderer {
|
||||
constructor(@Inject(DOCUMENT) private _doc: any /** TODO #9100 */) { super(); }
|
||||
|
||||
insertRootElement(rootElId: string) {
|
||||
let rootEl = el(`<div id="${rootElId}"></div>`);
|
||||
|
||||
// TODO(juliemr): can/should this be optional?
|
||||
let oldRoots = getDOM().querySelectorAll(this._doc, '[id^=root]');
|
||||
for (let i = 0; i < oldRoots.length; i++) {
|
||||
getDOM().remove(oldRoots[i]);
|
||||
}
|
||||
getDOM().appendChild(this._doc.body, rootEl);
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
export * from '@angular/platform-browser/testing/e2e_util';
|
||||
|
||||
console.log(
|
||||
`platform-browser-dynamic/testing_e2e is deprecated, use platform-browser/testing_e2e instead`);
|
@ -12,10 +12,12 @@
|
||||
"moduleResolution": "node",
|
||||
"outDir": "../../../dist/packages-dist/platform-browser-dynamic/esm",
|
||||
"paths": {
|
||||
"@angular/common": ["../../../dist/packages-dist/common/"],
|
||||
"@angular/compiler": ["../../../dist/packages-dist/compiler/"],
|
||||
"@angular/core": ["../../../dist/packages-dist/core"],
|
||||
"@angular/core/testing": ["../../../dist/packages-dist/core/testing"],
|
||||
"@angular/common": ["../../../dist/packages-dist/common"],
|
||||
"@angular/common/testing": ["../../../dist/packages-dist/common/testing"],
|
||||
"@angular/compiler": ["../../../dist/packages-dist/compiler"],
|
||||
"@angular/compiler/testing": ["../../../dist/packages-dist/compiler/testing"],
|
||||
"@angular/core": ["../../../dist/packages-dist/core/"],
|
||||
"@angular/platform-browser": ["../../../dist/packages-dist/platform-browser"],
|
||||
"@angular/platform-browser/testing": ["../../../dist/packages-dist/platform-browser/testing"]
|
||||
},
|
||||
@ -27,9 +29,7 @@
|
||||
"files": [
|
||||
"index.ts",
|
||||
"testing.ts",
|
||||
"../../../node_modules/@types/hammerjs/index.d.ts",
|
||||
"../../../node_modules/@types/protractor/index.d.ts",
|
||||
"../../../node_modules/@types/jasmine/index.d.ts",
|
||||
"../../../node_modules/zone.js/dist/zone.js.d.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,9 @@
|
||||
"outDir": "../../../dist/packages-dist/platform-browser-dynamic/",
|
||||
"paths": {
|
||||
"@angular/core": ["../../../dist/packages-dist/core"],
|
||||
"@angular/core/testing": ["../../../dist/packages-dist/core/testing"],
|
||||
"@angular/common": ["../../../dist/packages-dist/common"],
|
||||
"@angular/common/testing": ["../../../dist/packages-dist/common/testing"],
|
||||
"@angular/compiler": ["../../../dist/packages-dist/compiler"],
|
||||
"@angular/compiler/testing": ["../../../dist/packages-dist/compiler/testing"],
|
||||
"@angular/platform-browser": ["../../../dist/packages-dist/platform-browser"],
|
||||
@ -28,9 +30,7 @@
|
||||
"files": [
|
||||
"index.ts",
|
||||
"testing.ts",
|
||||
"../../../node_modules/@types/hammerjs/index.d.ts",
|
||||
"../../../node_modules/@types/protractor/index.d.ts",
|
||||
"../../../node_modules/@types/jasmine/index.d.ts",
|
||||
"../../../node_modules/zone.js/dist/zone.js.d.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user