refactor(browser): merge static & dynamic platforms
This commit is contained in:
@ -1 +0,0 @@
|
||||
export '../core/private_export.dart';
|
@ -1,4 +0,0 @@
|
||||
import {__core_private__ as r, __core_private_types__ as t} from '@angular/core';
|
||||
|
||||
export type ReflectionCapabilities = t.ReflectionCapabilities;
|
||||
export var ReflectionCapabilities: typeof t.ReflectionCapabilities = r.ReflectionCapabilities;
|
@ -1,4 +0,0 @@
|
||||
export * from './src/platform_browser_dynamic';
|
||||
|
||||
export * from './src/worker_render';
|
||||
export * from './src/worker_app';
|
@ -1,20 +0,0 @@
|
||||
{
|
||||
"name": "@angular/platform-browser-dynamic",
|
||||
"version": "$$ANGULAR_VERSION$$",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"jsnext:main": "esm/index.js",
|
||||
"typings": "index.d.ts",
|
||||
"author": "angular",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"@angular/core": "$$ANGULAR_VERSION$$",
|
||||
"@angular/common": "$$ANGULAR_VERSION$$",
|
||||
"@angular/compiler": "$$ANGULAR_VERSION$$",
|
||||
"@angular/platform-browser": "$$ANGULAR_VERSION$$"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/angular/angular.git"
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
export '../core/private_export.dart';
|
@ -1,7 +0,0 @@
|
||||
import {__platform_browser_private__ as _} from '@angular/platform-browser';
|
||||
|
||||
export type DomAdapter = _.DomAdapter;
|
||||
export function getDOM(): _.DomAdapter {
|
||||
return _.getDOM()
|
||||
}
|
||||
|
@ -1,20 +0,0 @@
|
||||
|
||||
export default {
|
||||
entry: '../../../dist/packages-dist/platform-browser-dynamic/esm/index.js',
|
||||
dest: '../../../dist/packages-dist/platform-browser-dynamic/esm/platform-browser-dynamic.umd.js',
|
||||
format: 'umd',
|
||||
moduleName: 'ng.platformBrowserDynamic',
|
||||
globals: {
|
||||
'@angular/core': 'ng.core',
|
||||
'@angular/common': 'ng.common',
|
||||
'@angular/compiler': 'ng.compiler',
|
||||
'@angular/platform-browser': 'ng.platformBrowser',
|
||||
'rxjs/Subject': 'Rx',
|
||||
'rxjs/observable/PromiseObservable': 'Rx', // this is wrong, but this stuff has changed in rxjs b.6 so we need to fix it when we update.
|
||||
'rxjs/operator/toPromise': 'Rx.Observable.prototype',
|
||||
'rxjs/Observable': 'Rx'
|
||||
},
|
||||
plugins: [
|
||||
// nodeResolve({ jsnext: true, main: true }),
|
||||
]
|
||||
}
|
@ -1 +0,0 @@
|
||||
../../facade/src
|
@ -1,108 +0,0 @@
|
||||
import {
|
||||
reflector,
|
||||
ReflectiveInjector,
|
||||
coreLoadAndBootstrap,
|
||||
Type,
|
||||
ComponentRef
|
||||
} from '@angular/core';
|
||||
|
||||
import {COMPILER_PROVIDERS, XHR} from '@angular/compiler';
|
||||
import {CachedXHR} from '../src/xhr/xhr_cache';
|
||||
import {isPresent} from '../src/facade/lang';
|
||||
import {XHRImpl} from '../src/xhr/xhr_impl';
|
||||
import {
|
||||
browserPlatform,
|
||||
BROWSER_APP_COMMON_PROVIDERS,
|
||||
} from '@angular/platform-browser';
|
||||
import {ReflectionCapabilities} from '../core_private';
|
||||
|
||||
export const CACHED_TEMPLATE_PROVIDER: Array<any /*Type | Provider | any[]*/> =
|
||||
/*@ts2dart_const*/[{provide: XHR, useClass: CachedXHR}];
|
||||
|
||||
/**
|
||||
* An array of providers that should be passed into `application()` when bootstrapping a component.
|
||||
*/
|
||||
export const BROWSER_APP_DYNAMIC_PROVIDERS: Array<any /*Type | Provider | any[]*/> =
|
||||
/*@ts2dart_const*/[
|
||||
BROWSER_APP_COMMON_PROVIDERS,
|
||||
COMPILER_PROVIDERS,
|
||||
{provide: XHR, useClass: XHRImpl},
|
||||
];
|
||||
|
||||
/**
|
||||
* 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();
|
||||
var appInjector = ReflectiveInjector.resolveAndCreate(
|
||||
[BROWSER_APP_DYNAMIC_PROVIDERS, isPresent(customProviders) ? customProviders : []],
|
||||
browserPlatform().injector);
|
||||
return coreLoadAndBootstrap(appInjector, appComponentType);
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
/**
|
||||
* All channels used by angular's WebWorker components are listed here.
|
||||
* You should not use these channels in your application code.
|
||||
*/
|
||||
export const XHR_CHANNEL = "ng-XHR";
|
@ -1,23 +0,0 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {PRIMITIVE, ServiceMessageBrokerFactory} from '@angular/platform-browser';
|
||||
import {XHR_CHANNEL} from '../shared/messaging_api';
|
||||
import {XHR} from '@angular/compiler';
|
||||
import {FunctionWrapper} from '../../facade/lang';
|
||||
|
||||
/**
|
||||
* XHR requests triggered on the worker side are executed on the UI side.
|
||||
*
|
||||
* This is only strictly required for Dart where the isolates do not have access to XHRs.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
@Injectable()
|
||||
export class MessageBasedXHRImpl {
|
||||
constructor(private _brokerFactory: ServiceMessageBrokerFactory, private _xhr: XHR) {}
|
||||
|
||||
start(): void {
|
||||
var broker = this._brokerFactory.createMessageBroker(XHR_CHANNEL);
|
||||
broker.registerMethod("get", [PRIMITIVE], FunctionWrapper.bind(this._xhr.get, this._xhr),
|
||||
PRIMITIVE);
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {XHR} from '@angular/compiler';
|
||||
import {
|
||||
FnArg,
|
||||
UiArguments,
|
||||
ClientMessageBroker,
|
||||
ClientMessageBrokerFactory
|
||||
} from '@angular/platform-browser';
|
||||
import {XHR_CHANNEL} from '../shared/messaging_api';
|
||||
|
||||
/**
|
||||
* Implementation of compiler/xhr that relays XHR requests to the UI side where they are sent
|
||||
* and the result is proxied back to the worker.
|
||||
*
|
||||
* This is only strictly required for Dart where isolates do not have access to the XHRs.
|
||||
*/
|
||||
@Injectable()
|
||||
export class WebWorkerXHRImpl extends XHR {
|
||||
private _messageBroker: ClientMessageBroker;
|
||||
|
||||
constructor(messageBrokerFactory: ClientMessageBrokerFactory) {
|
||||
super();
|
||||
this._messageBroker = messageBrokerFactory.createMessageBroker(XHR_CHANNEL);
|
||||
}
|
||||
|
||||
get(url: string): Promise<string> {
|
||||
var fnArgs: FnArg[] = [new FnArg(url, null)];
|
||||
var args: UiArguments = new UiArguments("get", fnArgs);
|
||||
return this._messageBroker.runOnService(args, String);
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
import {WORKER_APP_APPLICATION_PROVIDERS, workerAppPlatform} from '@angular/platform-browser';
|
||||
import {COMPILER_PROVIDERS, XHR} from '@angular/compiler';
|
||||
import {WebWorkerXHRImpl} from './web_workers/worker/xhr_impl';
|
||||
import {isPresent} from './facade/lang';
|
||||
|
||||
import {
|
||||
PlatformRef,
|
||||
Type,
|
||||
ComponentRef,
|
||||
ReflectiveInjector,
|
||||
coreLoadAndBootstrap,
|
||||
} from '@angular/core';
|
||||
|
||||
export const WORKER_APP_DYNAMIC_APPLICATION_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
|
||||
WORKER_APP_APPLICATION_PROVIDERS,
|
||||
COMPILER_PROVIDERS,
|
||||
WebWorkerXHRImpl,
|
||||
/* @ts2dart_Provider */ {provide: XHR, useExisting: WebWorkerXHRImpl}
|
||||
];
|
||||
|
||||
export function bootstrapApp(
|
||||
appComponentType: Type,
|
||||
customProviders?: Array<any /*Type | Provider | any[]*/>): Promise<ComponentRef<any>> {
|
||||
var appInjector = ReflectiveInjector.resolveAndCreate(
|
||||
[WORKER_APP_DYNAMIC_APPLICATION_PROVIDERS, isPresent(customProviders) ? customProviders : []],
|
||||
workerAppPlatform().injector);
|
||||
return coreLoadAndBootstrap(appInjector, appComponentType);
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
import {XHR} from "@angular/compiler";
|
||||
import {XHRImpl} from "./xhr/xhr_impl";
|
||||
import {MessageBasedXHRImpl} from "./web_workers/ui/xhr_impl";
|
||||
import {
|
||||
WORKER_RENDER_APPLICATION_PROVIDERS,
|
||||
WORKER_RENDER_STARTABLE_MESSAGING_SERVICE
|
||||
} from '@angular/platform-browser';
|
||||
import {
|
||||
ApplicationRef,
|
||||
PlatformRef,
|
||||
ReflectiveInjector,
|
||||
} from '@angular/core';
|
||||
import {workerRenderPlatform, WORKER_SCRIPT} from '@angular/platform-browser';
|
||||
import {isPresent} from './facade/lang';
|
||||
import {PromiseWrapper} from './facade/async';
|
||||
|
||||
export const WORKER_RENDER_DYNAMIC_APPLICATION_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
|
||||
WORKER_RENDER_APPLICATION_PROVIDERS,
|
||||
/* @ts2dart_Provider */ {provide: XHR, useClass: XHRImpl},
|
||||
MessageBasedXHRImpl,
|
||||
/* @ts2dart_Provider */ {provide: WORKER_RENDER_STARTABLE_MESSAGING_SERVICE, useExisting: MessageBasedXHRImpl, multi: true},
|
||||
];
|
||||
|
||||
export function bootstrapRender(
|
||||
workerScriptUri: string,
|
||||
customProviders?: Array<any /*Type | Provider | any[]*/>): Promise<ApplicationRef> {
|
||||
var app = ReflectiveInjector.resolveAndCreate(
|
||||
[
|
||||
WORKER_RENDER_DYNAMIC_APPLICATION_PROVIDERS,
|
||||
/* @ts2dart_Provider */ {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));
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
library angular2.src.services.xhr_cache;
|
||||
|
||||
import 'dart:async' show Future;
|
||||
import 'dart:html';
|
||||
import 'dart:js' as js;
|
||||
import 'package:angular2/core.dart';
|
||||
import 'package:angular2/src/compiler/xhr.dart';
|
||||
import 'package:angular2/src/facade/exceptions.dart' show BaseException;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@Injectable()
|
||||
class CachedXHR extends XHR {
|
||||
js.JsObject _cache;
|
||||
String _baseUri;
|
||||
|
||||
CachedXHR() {
|
||||
if (js.context.hasProperty(r'$templateCache')) {
|
||||
this._cache = js.context[r'$templateCache'];
|
||||
} else {
|
||||
throw new BaseException(
|
||||
r'CachedXHR: Template cache was not found in $templateCache.');
|
||||
}
|
||||
this._baseUri = window.location.protocol +
|
||||
'//' +
|
||||
window.location.host +
|
||||
window.location.pathname;
|
||||
int lastSlash = this._baseUri.lastIndexOf('/');
|
||||
this._baseUri = this._baseUri.substring(0, lastSlash + 1);
|
||||
}
|
||||
|
||||
Future<String> get(String url) {
|
||||
if (url.startsWith(this._baseUri)) {
|
||||
url = url.substring(this._baseUri.length);
|
||||
}
|
||||
if (this._cache.hasProperty(url)) {
|
||||
return new Future.value(this._cache[url]);
|
||||
} else {
|
||||
return new Future.error(
|
||||
'CachedXHR: Did not find cached template for ' + url);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
import {XHR} from '@angular/compiler';
|
||||
import {BaseException} from '../../src/facade/exceptions';
|
||||
import {global} from '../../src/facade/lang';
|
||||
import {PromiseWrapper} from '../../src/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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
library angular2.src.services.xhr_impl;
|
||||
|
||||
import 'dart:async' show Future;
|
||||
import 'dart:html' show HttpRequest;
|
||||
import 'package:angular2/core.dart';
|
||||
import 'package:angular2/src/compiler/xhr.dart';
|
||||
|
||||
@Injectable()
|
||||
class XHRImpl extends XHR {
|
||||
Future<String> get(String url) {
|
||||
return HttpRequest.request(url).then((HttpRequest req) => req.responseText,
|
||||
onError: (_) => new Future.error('Failed to load $url'));
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
var compiler_1 = require('@angular/compiler');
|
||||
var promise_1 = require('../../src/facade/promise');
|
||||
var lang_1 = require('../../src/facade/lang');
|
||||
var XHRImpl = (function (_super) {
|
||||
__extends(XHRImpl, _super);
|
||||
function XHRImpl() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
XHRImpl.prototype.get = function (url) {
|
||||
var completer = promise_1.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 = lang_1.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;
|
||||
};
|
||||
return XHRImpl;
|
||||
}(compiler_1.XHR));
|
||||
exports.XHRImpl = XHRImpl;
|
||||
//# sourceMappingURL=xhr_impl.js.map
|
@ -1,39 +0,0 @@
|
||||
import {XHR} from '@angular/compiler';
|
||||
import {PromiseWrapper, PromiseCompleter} from '../../src/facade/promise';
|
||||
import {isPresent} from '../../src/facade/lang';
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
<p>hey</p>
|
@ -1 +0,0 @@
|
||||
<span>from external template</span>
|
@ -1,7 +0,0 @@
|
||||
library angular2.test.testing.testing_browser_pec;
|
||||
|
||||
/**
|
||||
* This is intentionally left blank. The public test lib is only for TS/JS
|
||||
* apps.
|
||||
*/
|
||||
main() {}
|
@ -1,194 +0,0 @@
|
||||
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 '../../platform-browser-dynamic/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(() => [bind(FancyService).toValue(new FancyService())]);
|
||||
|
||||
it('provides a real XHR instance',
|
||||
inject([XHR], (xhr) => { expect(xhr).toBeAnInstanceOf(XHRImpl); }));
|
||||
|
||||
it('should allow the use of fakeAsync', fakeAsync(inject([FancyService], (service) => {
|
||||
var value;
|
||||
service.getAsyncValue().then(function(val) { 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) => {
|
||||
var done = () => { deferred.resolve() };
|
||||
(<any>done).fail = (err) => { deferred.reject(err) };
|
||||
fn(done);
|
||||
return null;
|
||||
};
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
var restoreJasmineIt = () => { jasmine.getEnv().it = originalJasmineIt; };
|
||||
|
||||
it('should fail when an XHR fails', (done) => {
|
||||
var itPromise = patchJasmineIt();
|
||||
|
||||
it('should fail with an error from a promise',
|
||||
async(inject([TestComponentBuilder],
|
||||
(tcb) => { 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'); });
|
||||
})));
|
||||
});
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
import {inject, describe, it, expect} from '@angular/core/testing/testing_internal';
|
||||
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
|
||||
|
||||
import {SpyMessageBroker} from '@angular/platform-browser/test/web_workers/worker/spies';
|
||||
import {WebWorkerXHRImpl} from '@angular/platform-browser-dynamic/src/web_workers/worker/xhr_impl';
|
||||
import {PromiseWrapper} from '../../../src/facade/async';
|
||||
import {
|
||||
MockMessageBrokerFactory,
|
||||
expectBrokerCall
|
||||
} from '@angular/platform-browser/test/web_workers/shared/web_worker_test_util';
|
||||
|
||||
export function main() {
|
||||
describe("WebWorkerXHRImpl", () => {
|
||||
it("should pass requests through the broker and return the response",
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
const URL = "http://www.example.com/test";
|
||||
const RESPONSE = "Example response text";
|
||||
|
||||
var messageBroker = new SpyMessageBroker();
|
||||
expectBrokerCall(messageBroker, "get", [URL],
|
||||
(_) => { return PromiseWrapper.wrap(() => { return RESPONSE; }); });
|
||||
var xhrImpl = new WebWorkerXHRImpl(new MockMessageBrokerFactory(<any>messageBroker));
|
||||
xhrImpl.get(URL).then((response) => {
|
||||
expect(response).toEqual(RESPONSE);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
import 'dart:js' as js;
|
||||
|
||||
void setTemplateCache(Map cache) {
|
||||
if (cache == null) {
|
||||
if (js.context.hasProperty(r'$templateCache')) {
|
||||
js.context.deleteProperty(r'$templateCache');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
js.JsObject jsMap = new js.JsObject(js.context['Object']);
|
||||
for (String key in cache.keys) {
|
||||
jsMap[key] = cache[key];
|
||||
}
|
||||
js.context[r'$templateCache'] = jsMap;
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
export function setTemplateCache(cache): void {
|
||||
(<any>window).$templateCache = cache;
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
import {Component, provide} from '@angular/core';
|
||||
import {UrlResolver, XHR} from '@angular/compiler';
|
||||
import {
|
||||
beforeEach,
|
||||
beforeEachProviders,
|
||||
ddescribe,
|
||||
describe,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xit
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {expect} from '@angular/platform-browser/testing';
|
||||
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
|
||||
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) => {
|
||||
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) => {
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
import {
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xit
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {AsyncTestCompleter} 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', () => {
|
||||
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 urlBase = IS_DART ? '' : '/base/modules/@angular/';
|
||||
var url200 = urlBase + 'platform-browser-dynamic/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) => {
|
||||
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) => {
|
||||
PromiseWrapper.catchError(xhr.get(url404), (e) => {
|
||||
expect(e).toEqual(`Failed to load ${url404}`);
|
||||
async.done();
|
||||
return null;
|
||||
});
|
||||
}), 10000);
|
||||
});
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
export * from './testing/browser';
|
||||
export * from './testing/dom_test_component_renderer';
|
@ -1,37 +0,0 @@
|
||||
import {
|
||||
TEST_BROWSER_STATIC_PLATFORM_PROVIDERS,
|
||||
ADDITIONAL_TEST_BROWSER_PROVIDERS
|
||||
} from '@angular/platform-browser/testing';
|
||||
import {BROWSER_APP_DYNAMIC_PROVIDERS} from '../index';
|
||||
import {DirectiveResolver, ViewResolver} from '@angular/compiler';
|
||||
import {
|
||||
MockDirectiveResolver,
|
||||
MockViewResolver,
|
||||
TestComponentRenderer,
|
||||
TestComponentBuilder
|
||||
} from '@angular/compiler/testing';
|
||||
import {DOMTestComponentRenderer} from './dom_test_component_renderer';
|
||||
|
||||
/**
|
||||
* Default platform providers for testing.
|
||||
*/
|
||||
export const TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS: Array<any /*Type | Provider | any[]*/> =
|
||||
/*@ts2dart_const*/[TEST_BROWSER_STATIC_PLATFORM_PROVIDERS];
|
||||
|
||||
|
||||
export const ADDITIONAL_DYNAMIC_TEST_BROWSER_PROVIDERS = [
|
||||
/*@ts2dart_Provider*/ {provide: DirectiveResolver, useClass: MockDirectiveResolver},
|
||||
/*@ts2dart_Provider*/ {provide: ViewResolver, useClass: MockViewResolver},
|
||||
TestComponentBuilder,
|
||||
/*@ts2dart_Provider*/ {provide: TestComponentRenderer, useClass: DOMTestComponentRenderer},
|
||||
];
|
||||
|
||||
/**
|
||||
* Default application providers for testing.
|
||||
*/
|
||||
export const TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS: Array<any /*Type | Provider | any[]*/> =
|
||||
/*@ts2dart_const*/[
|
||||
BROWSER_APP_DYNAMIC_PROVIDERS,
|
||||
ADDITIONAL_TEST_BROWSER_PROVIDERS,
|
||||
ADDITIONAL_DYNAMIC_TEST_BROWSER_PROVIDERS
|
||||
];
|
@ -1,24 +0,0 @@
|
||||
import {Inject, Injectable} from '@angular/core';
|
||||
import {DOCUMENT} from '@angular/platform-browser';
|
||||
import {getDOM} from '../platform_browser_private';
|
||||
import {TestComponentRenderer} from '@angular/compiler/testing';
|
||||
import {el} from '@angular/platform-browser/testing';
|
||||
|
||||
/**
|
||||
* A DOM based implementation of the TestComponentRenderer.
|
||||
*/
|
||||
@Injectable()
|
||||
export class DOMTestComponentRenderer extends TestComponentRenderer {
|
||||
constructor(@Inject(DOCUMENT) private _doc) { 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,33 +0,0 @@
|
||||
{
|
||||
"angularCompilerOptions": {
|
||||
"skipTemplateCodegen": true
|
||||
},
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"declaration": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"module": "es2015",
|
||||
"moduleResolution": "node",
|
||||
"outDir": "../../../dist/packages-dist/platform-browser-dynamic/esm",
|
||||
"paths": {
|
||||
"@angular/common": ["../../../dist/packages-dist/common/"],
|
||||
"@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"]
|
||||
},
|
||||
"rootDir": ".",
|
||||
"sourceMap": true,
|
||||
"inlineSources": true,
|
||||
"target": "es2015"
|
||||
},
|
||||
"files": [
|
||||
"index.ts",
|
||||
"testing.ts",
|
||||
"../typings/hammerjs/hammerjs.d.ts",
|
||||
"../typings/jasmine/jasmine.d.ts",
|
||||
"../../../node_modules/zone.js/dist/zone.js.d.ts"
|
||||
]
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
{
|
||||
"angularCompilerOptions": {
|
||||
"skipTemplateCodegen": true
|
||||
},
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"declaration": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"outDir": "../../../dist/packages-dist/platform-browser-dynamic/",
|
||||
"paths": {
|
||||
"@angular/core": ["../../../dist/packages-dist/core"],
|
||||
"@angular/common": ["../../../dist/packages-dist/common"],
|
||||
"@angular/compiler": ["../../../dist/packages-dist/compiler"],
|
||||
"@angular/compiler/testing": ["../../../dist/packages-dist/compiler/testing"],
|
||||
"@angular/platform-browser": ["../../../dist/packages-dist/platform-browser"],
|
||||
"@angular/platform-browser/testing": ["../../../dist/packages-dist/platform-browser/testing"]
|
||||
},
|
||||
"rootDir": ".",
|
||||
"sourceMap": true,
|
||||
"inlineSources": true,
|
||||
"target": "es5"
|
||||
},
|
||||
"files": [
|
||||
"index.ts",
|
||||
"testing.ts",
|
||||
"../typings/es6-collections/es6-collections.d.ts",
|
||||
"../typings/es6-promise/es6-promise.d.ts",
|
||||
"../manual_typings/globals.d.ts",
|
||||
"../typings/hammerjs/hammerjs.d.ts",
|
||||
"../typings/jasmine/jasmine.d.ts",
|
||||
"../../../node_modules/zone.js/dist/zone.js.d.ts"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user