chore: upgrade to new Zone.js API v0.6.2
BREAKING CHANGE Removed deprecated API from NgZone - `NgZone.overrideOnTurnStart` - `NgZone.overrideOnTurnDone` - `NgZone.overrideOnEventDone` - `NgZone.overrideOnErrorHandler` Rename NgZone API - `NgZone.onTurnStart` => `NgZone.onUnstable` - `NgZone.onTurnDone` => `NgZone.onMicrotaskEmpty` - `NgZone.onEventDone` => `NgZone.onStable` Closes #7345
This commit is contained in:
committed by
Miško Hevery
parent
f9fb72fb0e
commit
310620fd12
+4
-4
@@ -382,7 +382,7 @@ function proxyServeDart() {
|
||||
|
||||
// ------------------
|
||||
// web servers
|
||||
gulp.task('serve.js.dev', ['build.js.dev'], function(neverDone) {
|
||||
gulp.task('serve.js.dev', ['build.js.dev', 'build.js.cjs'], function(neverDone) {
|
||||
var watch = require('./tools/build/watch');
|
||||
|
||||
watch('modules/**', {ignoreInitial: true}, '!broccoli.js.dev');
|
||||
@@ -706,7 +706,7 @@ gulp.task('!build.payload.js.webpack', function() {
|
||||
.then(function() { // pad bundle with mandatory dependencies
|
||||
return new Promise(function(resolve, reject) {
|
||||
gulp.src([
|
||||
'node_modules/zone.js/dist/zone-microtask.js',
|
||||
'node_modules/zone.js/dist/zone.js',
|
||||
'node_modules/zone.js/dist/long-stack-trace-zone.js',
|
||||
'node_modules/reflect-metadata/Reflect.js',
|
||||
CASE_PATH + '/app-bundle.js'
|
||||
@@ -991,7 +991,7 @@ gulp.task('test.typings',
|
||||
['!pre.test.typings.layoutNodeModule', '!pre.test.typings.copyTypingsSpec'], function() {
|
||||
var tsc = require('gulp-typescript');
|
||||
|
||||
return gulp.src([tmpdir + '/*.ts'])
|
||||
return gulp.src([tmpdir + '/*.ts', 'node_modules/zone.js/dist/zone.js.d.ts'])
|
||||
.pipe(tsc({
|
||||
target: 'ES6',
|
||||
module: 'commonjs',
|
||||
@@ -1355,7 +1355,7 @@ gulp.task('!bundle.ng.polyfills', ['clean'],
|
||||
|
||||
var JS_DEV_DEPS = [
|
||||
licenseWrap('node_modules/zone.js/LICENSE', true),
|
||||
'node_modules/zone.js/dist/zone-microtask.js',
|
||||
'node_modules/zone.js/dist/zone.js',
|
||||
'node_modules/zone.js/dist/long-stack-trace-zone.js',
|
||||
licenseWrap('node_modules/reflect-metadata/LICENSE', true),
|
||||
'node_modules/reflect-metadata/Reflect.js'
|
||||
|
||||
+1
-2
@@ -17,8 +17,7 @@ module.exports = function(config) {
|
||||
// include Angular v1 for upgrade module testing
|
||||
'node_modules/angular/angular.min.js',
|
||||
|
||||
// zone-microtask must be included first as it contains a Promise monkey patch
|
||||
'node_modules/zone.js/dist/zone-microtask.js',
|
||||
'node_modules/zone.js/dist/zone.js',
|
||||
'node_modules/zone.js/dist/long-stack-trace-zone.js',
|
||||
'node_modules/zone.js/dist/jasmine-patch.js',
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {NgZone} from 'angular2/src/core/zone/ng_zone';
|
||||
import {NgZone, NgZoneError} from 'angular2/src/core/zone/ng_zone';
|
||||
import {
|
||||
Type,
|
||||
isBlank,
|
||||
@@ -254,7 +254,9 @@ export class PlatformRef_ extends PlatformRef {
|
||||
try {
|
||||
injector = this.injector.resolveAndCreateChild(providers);
|
||||
exceptionHandler = injector.get(ExceptionHandler);
|
||||
zone.overrideOnErrorHandler((e, s) => exceptionHandler.call(e, s));
|
||||
ObservableWrapper.subscribe(zone.onError, (error: NgZoneError) => {
|
||||
exceptionHandler.call(error.error, error.stackTrace);
|
||||
});
|
||||
} catch (e) {
|
||||
if (isPresent(exceptionHandler)) {
|
||||
exceptionHandler.call(e, e.stack);
|
||||
@@ -394,7 +396,7 @@ export class ApplicationRef_ extends ApplicationRef {
|
||||
constructor(private _platform: PlatformRef_, private _zone: NgZone, private _injector: Injector) {
|
||||
super();
|
||||
if (isPresent(this._zone)) {
|
||||
ObservableWrapper.subscribe(this._zone.onTurnDone,
|
||||
ObservableWrapper.subscribe(this._zone.onMicrotaskEmpty,
|
||||
(_) => { this._zone.run(() => { this.tick(); }); });
|
||||
}
|
||||
this._enforceNoNewChanges = assertionsEnabled();
|
||||
@@ -434,16 +436,10 @@ export class ApplicationRef_ extends ApplicationRef {
|
||||
|
||||
var tickResult = PromiseWrapper.then(compRefToken, tick);
|
||||
|
||||
// THIS MUST ONLY RUN IN DART.
|
||||
// This is required to report an error when no components with a matching selector found.
|
||||
// Otherwise the promise will never be completed.
|
||||
// Doing this in JS causes an extra error message to appear.
|
||||
if (IS_DART) {
|
||||
PromiseWrapper.then(tickResult, (_) => {});
|
||||
}
|
||||
|
||||
PromiseWrapper.then(tickResult, null,
|
||||
(err, stackTrace) => completer.reject(err, stackTrace));
|
||||
PromiseWrapper.then(tickResult, null, (err, stackTrace) => {
|
||||
completer.reject(err, stackTrace);
|
||||
exceptionHandler.call(err, stackTrace);
|
||||
});
|
||||
} catch (e) {
|
||||
exceptionHandler.call(e, e.stack);
|
||||
completer.reject(e, e.stack);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {Injectable} from 'angular2/src/core/di';
|
||||
import {Map, MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {CONST, CONST_EXPR} from 'angular2/src/facade/lang';
|
||||
import {BaseException, WrappedException} from 'angular2/src/facade/exceptions';
|
||||
import {CONST, CONST_EXPR, scheduleMicroTask} from 'angular2/src/facade/lang';
|
||||
import {BaseException} from 'angular2/src/facade/exceptions';
|
||||
import {NgZone} from '../zone/ng_zone';
|
||||
import {PromiseWrapper, ObservableWrapper} from 'angular2/src/facade/async';
|
||||
import {ObservableWrapper} from 'angular2/src/facade/async';
|
||||
|
||||
|
||||
/**
|
||||
@@ -15,6 +15,7 @@ import {PromiseWrapper, ObservableWrapper} from 'angular2/src/facade/async';
|
||||
export class Testability {
|
||||
/** @internal */
|
||||
_pendingCount: number = 0;
|
||||
_isZoneStable: boolean = true;
|
||||
/**
|
||||
* Whether any work was done since the last 'whenStable' callback. This is
|
||||
* useful to detect if this could have potentially destabilized another
|
||||
@@ -24,23 +25,22 @@ export class Testability {
|
||||
_didWork: boolean = false;
|
||||
/** @internal */
|
||||
_callbacks: Function[] = [];
|
||||
/** @internal */
|
||||
_isAngularEventPending: boolean = false;
|
||||
constructor(_ngZone: NgZone) { this._watchAngularEvents(_ngZone); }
|
||||
constructor(private _ngZone: NgZone) { this._watchAngularEvents(); }
|
||||
|
||||
/** @internal */
|
||||
_watchAngularEvents(_ngZone: NgZone): void {
|
||||
ObservableWrapper.subscribe(_ngZone.onTurnStart, (_) => {
|
||||
_watchAngularEvents(): void {
|
||||
ObservableWrapper.subscribe(this._ngZone.onUnstable, (_) => {
|
||||
this._didWork = true;
|
||||
this._isAngularEventPending = true;
|
||||
this._isZoneStable = false;
|
||||
});
|
||||
|
||||
_ngZone.runOutsideAngular(() => {
|
||||
ObservableWrapper.subscribe(_ngZone.onEventDone, (_) => {
|
||||
if (!_ngZone.hasPendingTimers) {
|
||||
this._isAngularEventPending = false;
|
||||
this._ngZone.runOutsideAngular(() => {
|
||||
ObservableWrapper.subscribe(this._ngZone.onStable, (_) => {
|
||||
NgZone.assertNotInAngularZone();
|
||||
scheduleMicroTask(() => {
|
||||
this._isZoneStable = true;
|
||||
this._runCallbacksIfReady();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -60,22 +60,24 @@ export class Testability {
|
||||
return this._pendingCount;
|
||||
}
|
||||
|
||||
isStable(): boolean { return this._pendingCount == 0 && !this._isAngularEventPending; }
|
||||
isStable(): boolean {
|
||||
return this._isZoneStable && this._pendingCount == 0 && !this._ngZone.hasPendingMacrotasks;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
_runCallbacksIfReady(): void {
|
||||
if (!this.isStable()) {
|
||||
if (this.isStable()) {
|
||||
// Schedules the call backs in a new frame so that it is always async.
|
||||
scheduleMicroTask(() => {
|
||||
while (this._callbacks.length !== 0) {
|
||||
(this._callbacks.pop())(this._didWork);
|
||||
}
|
||||
this._didWork = false;
|
||||
});
|
||||
} else {
|
||||
// Not Ready
|
||||
this._didWork = true;
|
||||
return; // Not ready
|
||||
}
|
||||
|
||||
// Schedules the call backs in a new frame so that it is always async.
|
||||
PromiseWrapper.resolve(null).then((_) => {
|
||||
while (this._callbacks.length !== 0) {
|
||||
(this._callbacks.pop())(this._didWork);
|
||||
}
|
||||
this._didWork = false;
|
||||
});
|
||||
}
|
||||
|
||||
whenStable(callback: Function): void {
|
||||
@@ -85,10 +87,6 @@ export class Testability {
|
||||
|
||||
getPendingRequestCount(): number { return this._pendingCount; }
|
||||
|
||||
// This only accounts for ngZone, and not pending counts. Use `whenStable` to
|
||||
// check for stability.
|
||||
isAngularEventPending(): boolean { return this._isAngularEventPending; }
|
||||
|
||||
findBindings(using: any, provider: string, exactMatch: boolean): any[] {
|
||||
// TODO(juliemr): implement.
|
||||
return [];
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
// Public API for Zone
|
||||
export {NgZone, ZeroArgFunction, ErrorHandlingFn, NgZoneError} from './zone/ng_zone';
|
||||
export {NgZone, NgZoneError} from './zone/ng_zone';
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,222 @@
|
||||
library angular.zone;
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:stack_trace/stack_trace.dart' show Chain;
|
||||
|
||||
typedef void ZeroArgFunction();
|
||||
typedef void ErrorHandlingFn(error, stackTrace);
|
||||
|
||||
/**
|
||||
* A `Timer` wrapper that lets you specify additional functions to call when it
|
||||
* is cancelled.
|
||||
*/
|
||||
class WrappedTimer implements Timer {
|
||||
Timer _timer;
|
||||
ZeroArgFunction _onCancelCb;
|
||||
|
||||
WrappedTimer(Timer timer) {
|
||||
_timer = timer;
|
||||
}
|
||||
|
||||
void addOnCancelCb(ZeroArgFunction onCancelCb) {
|
||||
if (this._onCancelCb != null) {
|
||||
throw "On cancel cb already registered";
|
||||
}
|
||||
this._onCancelCb = onCancelCb;
|
||||
}
|
||||
|
||||
void cancel() {
|
||||
if (this._onCancelCb != null) {
|
||||
this._onCancelCb();
|
||||
}
|
||||
_timer.cancel();
|
||||
}
|
||||
|
||||
bool get isActive => _timer.isActive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores error information; delivered via [NgZone.onError] stream.
|
||||
*/
|
||||
class NgZoneError {
|
||||
/// Error object thrown.
|
||||
final error;
|
||||
/// Either long or short chain of stack traces.
|
||||
final List stackTrace;
|
||||
NgZoneError(this.error, this.stackTrace);
|
||||
}
|
||||
|
||||
/**
|
||||
* A `Zone` wrapper that lets you schedule tasks after its private microtask queue is exhausted but
|
||||
* before the next "VM turn", i.e. event loop iteration.
|
||||
*
|
||||
* This lets you freely schedule microtasks that prepare data, and set an {@link onMicrotaskEmpty} handler that
|
||||
* will consume that data after it's ready but before the browser has a chance to re-render.
|
||||
*
|
||||
* A VM turn consist of a single macrotask followed 0 to many microtasks.
|
||||
*
|
||||
* The wrapper maintains an "inner" and "mount" `Zone`. The application code will executes
|
||||
* in the "inner" zone unless `runOutsideAngular` is explicitely called.
|
||||
*
|
||||
* A typical application will create a singleton `NgZone`. The mount zone is the `Zone` where the singleton has been
|
||||
* instantiated. The default `onMicrotaskEmpty` runs the Angular change detection.
|
||||
*/
|
||||
class NgZoneImpl {
|
||||
static bool isInAngularZone() {
|
||||
return Zone.current['isAngularZone'] == true;
|
||||
}
|
||||
|
||||
// Number of microtasks pending from _innerZone (& descendants)
|
||||
int _pendingMicrotasks = 0;
|
||||
List<Timer> _pendingTimers = [];
|
||||
Function onEnter;
|
||||
Function onLeave;
|
||||
Function setMicrotask;
|
||||
Function setMacrotask;
|
||||
Function onError;
|
||||
|
||||
Zone _outerZone;
|
||||
Zone _innerZone;
|
||||
/**
|
||||
* Associates with this
|
||||
*
|
||||
* - a "mount" [Zone], which is a the one that instantiated this.
|
||||
* - an "inner" [Zone], which is a child of the mount [Zone].
|
||||
*
|
||||
* @param {bool} trace whether to enable long stack trace. They should only be
|
||||
* enabled in development mode as they significantly impact perf.
|
||||
*/
|
||||
NgZoneImpl({
|
||||
bool trace,
|
||||
Function this.onEnter,
|
||||
Function this.onLeave,
|
||||
Function this.setMicrotask,
|
||||
Function this.setMacrotask,
|
||||
Function this.onError
|
||||
}) {
|
||||
_outerZone = Zone.current;
|
||||
|
||||
if (trace) {
|
||||
_innerZone = Chain.capture(
|
||||
() => _createInnerZone(Zone.current),
|
||||
onError: _onErrorWithLongStackTrace
|
||||
);
|
||||
} else {
|
||||
_innerZone = _createInnerZone(
|
||||
Zone.current,
|
||||
handleUncaughtError: _onErrorWithoutLongStackTrace
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Zone _createInnerZone(Zone zone, {handleUncaughtError}) {
|
||||
return zone.fork(
|
||||
specification: new ZoneSpecification(
|
||||
scheduleMicrotask: _scheduleMicrotask,
|
||||
run: _run,
|
||||
runUnary: _runUnary,
|
||||
runBinary: _runBinary,
|
||||
handleUncaughtError: handleUncaughtError,
|
||||
createTimer: _createTimer),
|
||||
zoneValues: {'isAngularZone': true}
|
||||
);
|
||||
}
|
||||
|
||||
dynamic runInner(fn()) {
|
||||
return _innerZone.runGuarded(fn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs `fn` in the mount zone and returns whatever it returns.
|
||||
*
|
||||
* In a typical app where the inner zone is the Angular zone, this allows one to escape Angular's
|
||||
* auto-digest mechanism.
|
||||
*
|
||||
* ```
|
||||
* void myFunction(NgZone zone, Element element) {
|
||||
* element.onClick.listen(() {
|
||||
* // auto-digest will run after element click.
|
||||
* });
|
||||
* zone.runOutsideAngular(() {
|
||||
* element.onMouseMove.listen(() {
|
||||
* // auto-digest will NOT run after mouse move
|
||||
* });
|
||||
* });
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
dynamic runOuter(fn()) {
|
||||
return _outerZone.run(fn);
|
||||
}
|
||||
|
||||
dynamic _run(Zone self, ZoneDelegate parent, Zone zone, fn()) {
|
||||
try {
|
||||
onEnter();
|
||||
return parent.run(zone, fn);
|
||||
} finally {
|
||||
onLeave();
|
||||
}
|
||||
}
|
||||
|
||||
dynamic _runUnary(Zone self, ZoneDelegate parent, Zone zone, fn(arg), arg) =>
|
||||
_run(self, parent, zone, () => fn(arg));
|
||||
|
||||
dynamic _runBinary(Zone self, ZoneDelegate parent, Zone zone, fn(arg1, arg2),
|
||||
arg1, arg2) =>
|
||||
_run(self, parent, zone, () => fn(arg1, arg2));
|
||||
|
||||
void _scheduleMicrotask(Zone self, ZoneDelegate parent, Zone zone, fn) {
|
||||
if (_pendingMicrotasks == 0) {
|
||||
setMicrotask(true);
|
||||
}
|
||||
_pendingMicrotasks++;
|
||||
var microtask = () {
|
||||
try {
|
||||
fn();
|
||||
} finally {
|
||||
_pendingMicrotasks--;
|
||||
if (_pendingMicrotasks == 0) {
|
||||
setMicrotask(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
parent.scheduleMicrotask(zone, microtask);
|
||||
}
|
||||
|
||||
// Called by Chain.capture() on errors when long stack traces are enabled
|
||||
void _onErrorWithLongStackTrace(error, Chain chain) {
|
||||
final traces = chain.terse.traces.map((t) => t.toString()).toList();
|
||||
onError(new NgZoneError(error, traces));
|
||||
}
|
||||
|
||||
// Outer zone handleUnchaughtError when long stack traces are not used
|
||||
void _onErrorWithoutLongStackTrace(Zone self, ZoneDelegate parent, Zone zone,
|
||||
error, StackTrace trace)
|
||||
{
|
||||
onError(new NgZoneError(error, [trace.toString()]));
|
||||
}
|
||||
|
||||
Timer _createTimer(
|
||||
Zone self, ZoneDelegate parent, Zone zone, Duration duration, fn()) {
|
||||
WrappedTimer wrappedTimer;
|
||||
var cb = () {
|
||||
try {
|
||||
fn();
|
||||
} finally {
|
||||
_pendingTimers.remove(wrappedTimer);
|
||||
setMacrotask(_pendingTimers.isNotEmpty);
|
||||
}
|
||||
};
|
||||
Timer timer = parent.createTimer(zone, duration, cb);
|
||||
wrappedTimer = new WrappedTimer(timer);
|
||||
wrappedTimer.addOnCancelCb(() {
|
||||
_pendingTimers.remove(wrappedTimer);
|
||||
setMacrotask(_pendingTimers.isNotEmpty);
|
||||
});
|
||||
|
||||
_pendingTimers.add(wrappedTimer);
|
||||
setMacrotask(true);
|
||||
return wrappedTimer;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
import {global} from 'angular2/src/facade/lang';
|
||||
|
||||
/**
|
||||
* Stores error information; delivered via [NgZone.onError] stream.
|
||||
*/
|
||||
export class NgZoneError {
|
||||
constructor(public error: any, public stackTrace: any) {}
|
||||
}
|
||||
|
||||
|
||||
export class NgZoneImpl implements ZoneSpec {
|
||||
static isInAngularZone(): boolean { return Zone.current.get('isAngularZone') === true; }
|
||||
|
||||
public name: string = 'angular';
|
||||
public properties: {[k: string]: string} = <any>{'isAngularZone': true};
|
||||
|
||||
private outer: Zone;
|
||||
private inner: Zone;
|
||||
|
||||
private onEnter: () => void;
|
||||
private onLeave: () => void;
|
||||
private setMicrotask: (hasMicrotasks: boolean) => void;
|
||||
private setMacrotask: (hasMacrotasks: boolean) => void;
|
||||
private onError: (error: NgZoneError) => void;
|
||||
|
||||
constructor({trace, onEnter, onLeave, setMicrotask, setMacrotask, onError}: {
|
||||
trace: boolean,
|
||||
onEnter: () => void,
|
||||
onLeave: () => void,
|
||||
setMicrotask: (hasMicrotasks: boolean) => void,
|
||||
setMacrotask: (hasMacrotasks: boolean) => void,
|
||||
onError: (error: NgZoneError) => void
|
||||
}) {
|
||||
this.onEnter = onEnter;
|
||||
this.onLeave = onLeave;
|
||||
this.setMicrotask = setMicrotask;
|
||||
this.setMacrotask = setMacrotask;
|
||||
this.onError = onError;
|
||||
|
||||
if (global.Zone) {
|
||||
this.outer = this.inner = Zone.current;
|
||||
if (Zone['wtfZoneSpec']) {
|
||||
this.inner = this.inner.fork(Zone['wtfZoneSpec']);
|
||||
}
|
||||
if (trace) {
|
||||
this.inner = this.inner.fork(Zone['longStackTraceZoneSpec']);
|
||||
}
|
||||
this.inner = this.inner.fork(this);
|
||||
} else {
|
||||
throw new Error('Angular2 needs to be run with Zone.js polyfill.');
|
||||
}
|
||||
}
|
||||
|
||||
onInvokeTask(delegate: ZoneDelegate, current: Zone, target: Zone, task: Task, applyThis: any,
|
||||
applyArgs: any): any {
|
||||
try {
|
||||
this.onEnter();
|
||||
return delegate.invokeTask(target, task, applyThis, applyArgs);
|
||||
} finally {
|
||||
this.onLeave();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
onInvoke(delegate: ZoneDelegate, current: Zone, target: Zone, callback: Function, applyThis: any,
|
||||
applyArgs: any[], source: string): any {
|
||||
try {
|
||||
this.onEnter();
|
||||
return delegate.invoke(target, callback, applyThis, applyArgs, source);
|
||||
} finally {
|
||||
this.onLeave();
|
||||
}
|
||||
}
|
||||
|
||||
onHasTask(delegate: ZoneDelegate, current: Zone, target: Zone, hasTaskState: HasTaskState) {
|
||||
delegate.hasTask(target, hasTaskState);
|
||||
if (current == target) {
|
||||
// We are only interested in hasTask events which originate from our zone
|
||||
// (A child hasTask event is not interesting to us)
|
||||
if (hasTaskState.change == 'microTask') {
|
||||
this.setMicrotask(hasTaskState.microTask);
|
||||
} else if (hasTaskState.change == 'macroTask') {
|
||||
this.setMacrotask(hasTaskState.macroTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onHandleError(delegate: ZoneDelegate, current: Zone, target: Zone, error: any): boolean {
|
||||
delegate.handleError(target, error);
|
||||
this.onError(new NgZoneError(error, error.stack));
|
||||
return false;
|
||||
}
|
||||
|
||||
runInner(fn: () => any): any { return this.inner.runGuarded(fn); };
|
||||
runOuter(fn: () => any): any { return this.outer.run(fn); };
|
||||
}
|
||||
@@ -3,7 +3,7 @@ library angular.core.facade.lang;
|
||||
export 'dart:core' show Type, RegExp, print, DateTime;
|
||||
import 'dart:math' as math;
|
||||
import 'dart:convert' as convert;
|
||||
import 'dart:async' show Future;
|
||||
import 'dart:async' show Future, Zone;
|
||||
|
||||
String getTypeNameForDebugging(Type type) => type.toString();
|
||||
|
||||
@@ -20,6 +20,10 @@ class CONST {
|
||||
|
||||
const IS_DART = true;
|
||||
|
||||
scheduleMicroTask(Function fn) {
|
||||
Zone.current.scheduleMicrotask(fn);
|
||||
}
|
||||
|
||||
bool isPresent(Object obj) => obj != null;
|
||||
bool isBlank(Object obj) => obj == null;
|
||||
bool isString(Object obj) => obj is String;
|
||||
|
||||
@@ -1,14 +1,3 @@
|
||||
// Zones are TC-39 standards-track so users could choose a different implementation
|
||||
// Rather than import {Zone} from 'zone.js' we define an interface
|
||||
// so that any library that structurally matches may be used with Angular 2.
|
||||
export interface ZoneLike {
|
||||
fork(locals?: any): ZoneLike;
|
||||
run(fn: any, applyTo?: any, applyWith?: any): any;
|
||||
}
|
||||
export interface ZoneLikeConstructor {
|
||||
longStackTraceZone: { [key: string]: any; };
|
||||
}
|
||||
|
||||
export interface BrowserNodeGlobal {
|
||||
Object: typeof Object;
|
||||
Array: typeof Array;
|
||||
@@ -20,8 +9,7 @@ export interface BrowserNodeGlobal {
|
||||
Math: any; // typeof Math;
|
||||
assert(condition: any): void;
|
||||
Reflect: any;
|
||||
zone: ZoneLike;
|
||||
Zone: ZoneLikeConstructor;
|
||||
Zone: typeof Zone;
|
||||
getAngularTestability: Function;
|
||||
getAllAngularTestabilities: Function;
|
||||
getAllAngularRootElements: Function;
|
||||
@@ -46,6 +34,10 @@ if (typeof window === 'undefined') {
|
||||
globalScope = <any>window;
|
||||
}
|
||||
|
||||
export function scheduleMicroTask(fn: Function) {
|
||||
Zone.current.scheduleMicroTask('scheduleMicrotask', fn);
|
||||
}
|
||||
|
||||
export const IS_DART = false;
|
||||
|
||||
// Need to declare a new variable for global here since TypeScript
|
||||
|
||||
@@ -8,18 +8,15 @@ import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
|
||||
@Injectable()
|
||||
export class MockNgZone extends NgZone {
|
||||
/** @internal */
|
||||
_mockOnEventDone: EventEmitter<any>;
|
||||
private _mockOnStable: EventEmitter<any> = new EventEmitter(false);
|
||||
|
||||
constructor() {
|
||||
super({enableLongStackTrace: false});
|
||||
this._mockOnEventDone = new EventEmitter<any>(false);
|
||||
}
|
||||
constructor() { super({enableLongStackTrace: false}); }
|
||||
|
||||
get onEventDone() { return this._mockOnEventDone; }
|
||||
get onStable() { return this._mockOnStable; }
|
||||
|
||||
run(fn: Function): any { return fn(); }
|
||||
|
||||
runOutsideAngular(fn: Function): any { return fn(); }
|
||||
|
||||
simulateZoneExit(): void { ObservableWrapper.callNext(this.onEventDone, null); }
|
||||
simulateZoneExit(): void { ObservableWrapper.callNext(this.onStable, null); }
|
||||
}
|
||||
|
||||
@@ -271,9 +271,9 @@ export class UnresolvedInstruction extends Instruction {
|
||||
if (isPresent(this.component)) {
|
||||
return PromiseWrapper.resolve(this.component);
|
||||
}
|
||||
return this._resolver().then((resolution: Instruction) => {
|
||||
this.child = resolution.child;
|
||||
return this.component = resolution.component;
|
||||
return this._resolver().then((instruction: Instruction) => {
|
||||
this.child = isPresent(instruction) ? instruction.child : null;
|
||||
return this.component = isPresent(instruction) ? instruction.component : null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,58 @@
|
||||
import {global} from 'angular2/src/facade/lang';
|
||||
import {BaseException, WrappedException} from 'angular2/src/facade/exceptions';
|
||||
import {BaseException} from 'angular2/src/facade/exceptions';
|
||||
import {ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {NgZoneZone} from 'angular2/src/core/zone/ng_zone';
|
||||
|
||||
var _scheduler;
|
||||
var _microtasks: Function[] = [];
|
||||
var _pendingPeriodicTimers: number[] = [];
|
||||
var _pendingTimers: number[] = [];
|
||||
|
||||
interface FakeAsyncZone extends NgZoneZone {
|
||||
_inFakeAsyncZone: boolean;
|
||||
class FakeAsyncZoneSpec implements ZoneSpec {
|
||||
static assertInZone(): void {
|
||||
if (!Zone.current.get('inFakeAsyncZone')) {
|
||||
throw new Error('The code should be running in the fakeAsync zone to call this function');
|
||||
}
|
||||
}
|
||||
|
||||
name: string = 'fakeAsync';
|
||||
|
||||
properties: {[key: string]: any} = {'inFakeAsyncZone': true};
|
||||
|
||||
onScheduleTask(delegate: ZoneDelegate, current: Zone, target: Zone, task: Task): Task {
|
||||
switch (task.type) {
|
||||
case 'microTask':
|
||||
_microtasks.push(task.invoke);
|
||||
break;
|
||||
case 'macroTask':
|
||||
switch (task.source) {
|
||||
case 'setTimeout':
|
||||
task.data['handleId'] = _setTimeout(task.invoke, task.data['delay'], task.data['args']);
|
||||
break;
|
||||
case 'setInterval':
|
||||
task.data['handleId'] =
|
||||
_setInterval(task.invoke, task.data['delay'], task.data['args']);
|
||||
break;
|
||||
default:
|
||||
task = delegate.scheduleTask(target, task);
|
||||
}
|
||||
break;
|
||||
case 'eventTask':
|
||||
task = delegate.scheduleTask(target, task);
|
||||
break;
|
||||
}
|
||||
return task;
|
||||
}
|
||||
|
||||
onCancelTask(delegate: ZoneDelegate, current: Zone, target: Zone, task: Task): any {
|
||||
switch (task.source) {
|
||||
case 'setTimeout':
|
||||
return _clearTimeout(task.data['handleId']);
|
||||
case 'setInterval':
|
||||
return _clearInterval(task.data['handleId']);
|
||||
default:
|
||||
return delegate.scheduleTask(target, task);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,18 +70,11 @@ interface FakeAsyncZone extends NgZoneZone {
|
||||
* @returns {Function} The function wrapped to be executed in the fakeAsync zone
|
||||
*/
|
||||
export function fakeAsync(fn: Function): Function {
|
||||
if ((<FakeAsyncZone>global.zone)._inFakeAsyncZone) {
|
||||
if (Zone.current.get('inFakeAsyncZone')) {
|
||||
throw new Error('fakeAsync() calls can not be nested');
|
||||
}
|
||||
|
||||
var fakeAsyncZone = <FakeAsyncZone>global.zone.fork({
|
||||
setTimeout: _setTimeout,
|
||||
clearTimeout: _clearTimeout,
|
||||
setInterval: _setInterval,
|
||||
clearInterval: _clearInterval,
|
||||
scheduleMicrotask: _scheduleMicrotask,
|
||||
_inFakeAsyncZone: true
|
||||
});
|
||||
var fakeAsyncZone = Zone.current.fork(new FakeAsyncZoneSpec());
|
||||
|
||||
return function(...args) {
|
||||
// TODO(tbosch): This class should already be part of the jasmine typings but it is not...
|
||||
@@ -97,7 +133,7 @@ export function clearPendingTimers(): void {
|
||||
* @param {number} millis Number of millisecond, defaults to 0
|
||||
*/
|
||||
export function tick(millis: number = 0): void {
|
||||
_assertInFakeAsyncZone();
|
||||
FakeAsyncZoneSpec.assertInZone();
|
||||
flushMicrotasks();
|
||||
_scheduler.tick(millis);
|
||||
}
|
||||
@@ -106,14 +142,14 @@ export function tick(millis: number = 0): void {
|
||||
* Flush any pending microtasks.
|
||||
*/
|
||||
export function flushMicrotasks(): void {
|
||||
_assertInFakeAsyncZone();
|
||||
FakeAsyncZoneSpec.assertInZone();
|
||||
while (_microtasks.length > 0) {
|
||||
var microtask = ListWrapper.removeAt(_microtasks, 0);
|
||||
microtask();
|
||||
}
|
||||
}
|
||||
|
||||
function _setTimeout(fn: Function, delay: number, ...args): number {
|
||||
function _setTimeout(fn: Function, delay: number, args: any[]): number {
|
||||
var cb = _fnAndFlush(fn);
|
||||
var id = _scheduler.scheduleFunction(cb, delay, args);
|
||||
_pendingTimers.push(id);
|
||||
@@ -145,16 +181,6 @@ function _fnAndFlush(fn: Function): Function {
|
||||
}
|
||||
}
|
||||
|
||||
function _scheduleMicrotask(microtask: Function): void {
|
||||
_microtasks.push(microtask);
|
||||
}
|
||||
|
||||
function _dequeueTimer(id: number): Function {
|
||||
return function() { ListWrapper.remove(_pendingTimers, id); }
|
||||
}
|
||||
|
||||
function _assertInFakeAsyncZone(): void {
|
||||
if (!global.zone || !(<FakeAsyncZone>global.zone)._inFakeAsyncZone) {
|
||||
throw new Error('The code should be running in the fakeAsync zone to call this function');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ export 'testing_internal_core.dart'
|
||||
xdescribe;
|
||||
|
||||
import 'package:angular2/platform/testing/browser.dart';
|
||||
import 'package:angular2/src/facade/collection.dart' show StringMapWrapper;
|
||||
import "package:angular2/src/core/zone/ng_zone.dart" show NgZone;
|
||||
|
||||
export 'test_injector.dart' show inject;
|
||||
|
||||
@@ -62,4 +64,6 @@ void ddescribe(name, fn) {
|
||||
void xdescribe(name, fn) {
|
||||
testSetup();
|
||||
core.xdescribe(name, fn);
|
||||
}
|
||||
}
|
||||
|
||||
bool isInInnerZone() => NgZone.isInAngularZone();
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
|
||||
import {StringMapWrapper} from 'angular2/src/facade/collection';
|
||||
import {global, isFunction, Math} from 'angular2/src/facade/lang';
|
||||
import {NgZoneZone} from 'angular2/src/core/zone/ng_zone';
|
||||
|
||||
import {provide} from 'angular2/core';
|
||||
|
||||
import {TestInjector, getTestInjector, FunctionWithParamTokens, inject} from './test_injector';
|
||||
import {getTestInjector, FunctionWithParamTokens, inject} from './test_injector';
|
||||
import {browserDetection} from './utils';
|
||||
import {NgZone} from 'angular2/src/core/zone/ng_zone';
|
||||
|
||||
export {inject} from './test_injector';
|
||||
|
||||
@@ -256,7 +255,3 @@ export class SpyObject {
|
||||
return newSpy;
|
||||
}
|
||||
}
|
||||
|
||||
export function isInInnerZone(): boolean {
|
||||
return (<NgZoneZone>global.zone)._innerZone === true;
|
||||
}
|
||||
|
||||
@@ -5,22 +5,21 @@ import {isPresent, isString, RegExpWrapper, StringWrapper, RegExp} from 'angular
|
||||
|
||||
@Injectable()
|
||||
export class Log {
|
||||
/** @internal */
|
||||
_result: any[];
|
||||
logItems: any[];
|
||||
|
||||
constructor() { this._result = []; }
|
||||
constructor() { this.logItems = []; }
|
||||
|
||||
add(value): void { this._result.push(value); }
|
||||
add(value): void { this.logItems.push(value); }
|
||||
|
||||
fn(value) {
|
||||
return (a1: any = null, a2: any = null, a3: any = null, a4: any = null, a5: any = null) => {
|
||||
this._result.push(value);
|
||||
this.logItems.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
clear(): void { this._result = []; }
|
||||
clear(): void { this.logItems = []; }
|
||||
|
||||
result(): string { return this._result.join("; "); }
|
||||
result(): string { return this.logItems.join("; "); }
|
||||
}
|
||||
|
||||
export var browserDetection: BrowserDetection = null;
|
||||
|
||||
@@ -338,7 +338,7 @@ export class UpgradeAdapter {
|
||||
'$rootScope',
|
||||
(injector: angular.IInjectorService, rootScope: angular.IRootScopeService) => {
|
||||
ng1Injector = injector;
|
||||
ObservableWrapper.subscribe(ngZone.onTurnDone,
|
||||
ObservableWrapper.subscribe(ngZone.onMicrotaskEmpty,
|
||||
(_) => ngZone.runOutsideAngular(() => rootScope.$apply()));
|
||||
ng1compilePromise =
|
||||
UpgradeNg1ComponentAdapterBuilder.resolve(this.downgradedComponents, injector);
|
||||
|
||||
@@ -46,7 +46,7 @@ abstract class GenericMessageBusSink implements MessageBusSink {
|
||||
void attachToZone(NgZone zone) {
|
||||
_zone = zone;
|
||||
_zone.runOutsideAngular(() {
|
||||
_zone.onEventDone.listen((_) {
|
||||
_zone.onStable.listen((_) {
|
||||
if (_messageBuffer.length > 0) {
|
||||
sendMessages(_messageBuffer);
|
||||
_messageBuffer.clear();
|
||||
|
||||
@@ -22,7 +22,7 @@ export class PostMessageBusSink implements MessageBusSink {
|
||||
attachToZone(zone: NgZone): void {
|
||||
this._zone = zone;
|
||||
this._zone.runOutsideAngular(() => {
|
||||
ObservableWrapper.subscribe(this._zone.onEventDone, (_) => { this._handleOnEventDone(); });
|
||||
ObservableWrapper.subscribe(this._zone.onStable, (_) => { this._handleOnEventDone(); });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ export function main() {
|
||||
TimerWrapper.setTimeout(() => {
|
||||
expect(ref.spy('markForCheck')).toHaveBeenCalled();
|
||||
async.done();
|
||||
}, 0)
|
||||
}, 10)
|
||||
}));
|
||||
});
|
||||
|
||||
@@ -121,7 +121,7 @@ export function main() {
|
||||
var completer: PromiseCompleter<any>;
|
||||
var ref: SpyChangeDetectorRef;
|
||||
// adds longer timers for passing tests in IE
|
||||
var timer = (!isBlank(DOM) && browserDetection.isIE) ? 50 : 0;
|
||||
var timer = (!isBlank(DOM) && browserDetection.isIE) ? 50 : 10;
|
||||
|
||||
beforeEach(() => {
|
||||
completer = PromiseWrapper.completer();
|
||||
@@ -174,11 +174,12 @@ export function main() {
|
||||
|
||||
it("should request a change detection check upon receiving a new value",
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
var markForCheck = ref.spy('markForCheck');
|
||||
pipe.transform(completer.promise);
|
||||
completer.resolve(message);
|
||||
|
||||
TimerWrapper.setTimeout(() => {
|
||||
expect(ref.spy('markForCheck')).toHaveBeenCalled();
|
||||
expect(markForCheck).toHaveBeenCalled();
|
||||
async.done();
|
||||
}, timer)
|
||||
}));
|
||||
|
||||
@@ -20,6 +20,8 @@ import {Injector, Provider, APP_INITIALIZER} from "angular2/core";
|
||||
import {ChangeDetectorRef_} from "angular2/src/core/change_detection/change_detector_ref";
|
||||
import {PromiseWrapper, PromiseCompleter, TimerWrapper} from "angular2/src/facade/async";
|
||||
import {ListWrapper} from "angular2/src/facade/collection";
|
||||
import {ExceptionHandler} from 'angular2/src/facade/exception_handler';
|
||||
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
|
||||
|
||||
export function main() {
|
||||
describe("ApplicationRef", () => {
|
||||
@@ -33,6 +35,8 @@ export function main() {
|
||||
});
|
||||
|
||||
describe("PlatformRef", () => {
|
||||
var exceptionHandler =
|
||||
new Provider(ExceptionHandler, {useValue: new ExceptionHandler(DOM, true)});
|
||||
describe("asyncApplication", () => {
|
||||
function expectProviders(injector: Injector, providers: Array<any>): void {
|
||||
for (let i = 0; i < providers.length; i++) {
|
||||
@@ -44,7 +48,7 @@ export function main() {
|
||||
it("should merge syncronous and asyncronous providers",
|
||||
inject([AsyncTestCompleter, Injector], (async, injector) => {
|
||||
let ref = new PlatformRef_(injector, null);
|
||||
let ASYNC_PROVIDERS = [new Provider(Foo, {useValue: new Foo()})];
|
||||
let ASYNC_PROVIDERS = [new Provider(Foo, {useValue: new Foo()}), exceptionHandler];
|
||||
let SYNC_PROVIDERS = [new Provider(Bar, {useValue: new Bar()})];
|
||||
ref.asyncApplication((zone) => PromiseWrapper.resolve(ASYNC_PROVIDERS), SYNC_PROVIDERS)
|
||||
.then((appRef) => {
|
||||
@@ -57,7 +61,7 @@ export function main() {
|
||||
it("should allow function to be null",
|
||||
inject([AsyncTestCompleter, Injector], (async, injector) => {
|
||||
let ref = new PlatformRef_(injector, null);
|
||||
let SYNC_PROVIDERS = [new Provider(Bar, {useValue: new Bar()})];
|
||||
let SYNC_PROVIDERS = [new Provider(Bar, {useValue: new Bar()}), exceptionHandler];
|
||||
ref.asyncApplication(null, SYNC_PROVIDERS)
|
||||
.then((appRef) => {
|
||||
expectProviders(appRef.injector, SYNC_PROVIDERS);
|
||||
@@ -86,7 +90,7 @@ export function main() {
|
||||
new Provider(APP_INITIALIZER,
|
||||
{useValue: mockAsyncAppInitializer(completer), multi: true})
|
||||
];
|
||||
ref.asyncApplication(null, SYNC_PROVIDERS)
|
||||
ref.asyncApplication(null, [SYNC_PROVIDERS, exceptionHandler])
|
||||
.then((appRef) => {
|
||||
expectProviders(appRef.injector,
|
||||
SYNC_PROVIDERS.slice(0, SYNC_PROVIDERS.length - 1));
|
||||
@@ -109,7 +113,8 @@ export function main() {
|
||||
deps: [Injector]
|
||||
})
|
||||
];
|
||||
ref.asyncApplication((zone) => PromiseWrapper.resolve(ASYNC_PROVIDERS), SYNC_PROVIDERS)
|
||||
ref.asyncApplication((zone) => PromiseWrapper.resolve(ASYNC_PROVIDERS),
|
||||
[SYNC_PROVIDERS, exceptionHandler])
|
||||
.then((appRef) => {
|
||||
expectProviders(appRef.injector,
|
||||
SYNC_PROVIDERS.slice(0, SYNC_PROVIDERS.length - 1));
|
||||
@@ -123,7 +128,7 @@ export function main() {
|
||||
let ref = new PlatformRef_(injector, null);
|
||||
let appInitializer = new Provider(
|
||||
APP_INITIALIZER, {useValue: () => PromiseWrapper.resolve([]), multi: true});
|
||||
expect(() => ref.application([appInitializer]))
|
||||
expect(() => ref.application([appInitializer, exceptionHandler]))
|
||||
.toThrowError(
|
||||
"Cannot use asyncronous app initializers with application. Use asyncApplication instead.");
|
||||
}));
|
||||
|
||||
@@ -128,7 +128,7 @@ export function main() {
|
||||
}));
|
||||
});
|
||||
|
||||
it('should handle swapping element', () => {
|
||||
it('should handle incremental swapping element', () => {
|
||||
let l = ['a', 'b', 'c'];
|
||||
differ.check(l);
|
||||
|
||||
|
||||
@@ -14,36 +14,43 @@ import {
|
||||
} from 'angular2/testing_internal';
|
||||
import {Testability} from 'angular2/src/core/testability/testability';
|
||||
import {NgZone} from 'angular2/src/core/zone/ng_zone';
|
||||
import {normalizeBlank} from 'angular2/src/facade/lang';
|
||||
import {normalizeBlank, scheduleMicroTask} from 'angular2/src/facade/lang';
|
||||
import {PromiseWrapper, EventEmitter, ObservableWrapper} from 'angular2/src/facade/async';
|
||||
|
||||
// Schedules a microtasks (using a resolved promise .then())
|
||||
function microTask(fn: Function): void {
|
||||
PromiseWrapper.resolve(null).then((_) => { fn(); });
|
||||
scheduleMicroTask(() => {
|
||||
// We do double dispatch so that we can wait for scheduleMicrotas in the Testability when
|
||||
// NgZone becomes stable.
|
||||
scheduleMicroTask(fn);
|
||||
});
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
class MockNgZone extends NgZone {
|
||||
_onTurnStartStream: EventEmitter<any>;
|
||||
get onTurnStart() { return this._onTurnStartStream; }
|
||||
_onUnstableStream: EventEmitter<any>;
|
||||
get onUnstable() { return this._onUnstableStream; }
|
||||
|
||||
_onEventDoneStream: EventEmitter<any>;
|
||||
get onEventDone() { return this._onEventDoneStream; }
|
||||
_onStableStream: EventEmitter<any>;
|
||||
get onStable() { return this._onStableStream; }
|
||||
|
||||
constructor() {
|
||||
super({enableLongStackTrace: false});
|
||||
this._onTurnStartStream = new EventEmitter(false);
|
||||
this._onEventDoneStream = new EventEmitter(false);
|
||||
this._onUnstableStream = new EventEmitter(false);
|
||||
this._onStableStream = new EventEmitter(false);
|
||||
}
|
||||
|
||||
start(): void { ObservableWrapper.callEmit(this._onTurnStartStream, null); }
|
||||
unstable(): void { ObservableWrapper.callEmit(this._onUnstableStream, null); }
|
||||
|
||||
finish(): void { ObservableWrapper.callEmit(this._onEventDoneStream, null); }
|
||||
stable(): void { ObservableWrapper.callEmit(this._onStableStream, null); }
|
||||
}
|
||||
|
||||
export function main() {
|
||||
describe('Testability', () => {
|
||||
var testability, execute, execute2, ngZone;
|
||||
var testability: Testability;
|
||||
var execute: any;
|
||||
var execute2: any;
|
||||
var ngZone: MockNgZone;
|
||||
|
||||
beforeEach(() => {
|
||||
ngZone = new MockNgZone();
|
||||
@@ -142,13 +149,10 @@ export function main() {
|
||||
});
|
||||
|
||||
describe('NgZone callback logic', () => {
|
||||
it('should start being ready',
|
||||
() => { expect(testability.isAngularEventPending()).toEqual(false); });
|
||||
|
||||
it('should fire whenstable callback if event is already finished',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
ngZone.start();
|
||||
ngZone.finish();
|
||||
ngZone.unstable();
|
||||
ngZone.stable();
|
||||
testability.whenStable(execute);
|
||||
|
||||
microTask(() => {
|
||||
@@ -158,8 +162,8 @@ export function main() {
|
||||
}));
|
||||
|
||||
it('should not fire whenstable callbacks synchronously if event is already finished', () => {
|
||||
ngZone.start();
|
||||
ngZone.finish();
|
||||
ngZone.unstable();
|
||||
ngZone.stable();
|
||||
testability.whenStable(execute);
|
||||
|
||||
expect(execute).not.toHaveBeenCalled();
|
||||
@@ -167,12 +171,12 @@ export function main() {
|
||||
|
||||
it('should fire whenstable callback when event finishes',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
ngZone.start();
|
||||
ngZone.unstable();
|
||||
testability.whenStable(execute);
|
||||
|
||||
microTask(() => {
|
||||
expect(execute).not.toHaveBeenCalled();
|
||||
ngZone.finish();
|
||||
ngZone.stable();
|
||||
|
||||
microTask(() => {
|
||||
expect(execute).toHaveBeenCalled();
|
||||
@@ -182,16 +186,16 @@ export function main() {
|
||||
}));
|
||||
|
||||
it('should not fire whenstable callbacks synchronously when event finishes', () => {
|
||||
ngZone.start();
|
||||
ngZone.unstable();
|
||||
testability.whenStable(execute);
|
||||
ngZone.finish();
|
||||
ngZone.stable();
|
||||
|
||||
expect(execute).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not fire whenstable callback when event did not finish',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
ngZone.start();
|
||||
ngZone.unstable();
|
||||
testability.increasePendingRequestCount();
|
||||
testability.whenStable(execute);
|
||||
|
||||
@@ -201,7 +205,7 @@ export function main() {
|
||||
|
||||
microTask(() => {
|
||||
expect(execute).not.toHaveBeenCalled();
|
||||
ngZone.finish();
|
||||
ngZone.stable();
|
||||
|
||||
microTask(() => {
|
||||
expect(execute).toHaveBeenCalled();
|
||||
@@ -213,14 +217,14 @@ export function main() {
|
||||
|
||||
it('should not fire whenstable callback when there are pending counts',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
ngZone.start();
|
||||
ngZone.unstable();
|
||||
testability.increasePendingRequestCount();
|
||||
testability.increasePendingRequestCount();
|
||||
testability.whenStable(execute);
|
||||
|
||||
microTask(() => {
|
||||
expect(execute).not.toHaveBeenCalled();
|
||||
ngZone.finish();
|
||||
ngZone.stable();
|
||||
|
||||
microTask(() => {
|
||||
expect(execute).not.toHaveBeenCalled();
|
||||
@@ -241,8 +245,8 @@ export function main() {
|
||||
|
||||
it('should fire whenstable callback with didWork if event is already finished',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
ngZone.start();
|
||||
ngZone.finish();
|
||||
ngZone.unstable();
|
||||
ngZone.stable();
|
||||
testability.whenStable(execute);
|
||||
|
||||
microTask(() => {
|
||||
@@ -258,11 +262,11 @@ export function main() {
|
||||
|
||||
it('should fire whenstable callback with didwork when event finishes',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
ngZone.start();
|
||||
ngZone.unstable();
|
||||
testability.whenStable(execute);
|
||||
|
||||
microTask(() => {
|
||||
ngZone.finish();
|
||||
ngZone.stable();
|
||||
|
||||
microTask(() => {
|
||||
expect(execute).toHaveBeenCalledWith(true);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -20,10 +20,10 @@ import {Component, Directive, OnDestroy, platform} from 'angular2/core';
|
||||
import {BROWSER_PROVIDERS, BROWSER_APP_PROVIDERS} from 'angular2/platform/browser';
|
||||
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
|
||||
import {DOCUMENT} from 'angular2/src/platform/dom/dom_tokens';
|
||||
import {PromiseWrapper} from 'angular2/src/facade/async';
|
||||
import {PromiseWrapper, TimerWrapper} from 'angular2/src/facade/async';
|
||||
import {provide, Inject, Injector, PLATFORM_INITIALIZER, APP_INITIALIZER} from 'angular2/core';
|
||||
import {disposePlatform} from 'angular2/src/core/application_ref';
|
||||
import {ExceptionHandler} from 'angular2/src/facade/exceptions';
|
||||
import {ExceptionHandler, BaseException} from 'angular2/src/facade/exceptions';
|
||||
import {Testability, TestabilityRegistry} from 'angular2/src/core/testability/testability';
|
||||
import {ComponentRef_, ComponentRef} from "angular2/src/core/linker/dynamic_component_loader";
|
||||
|
||||
@@ -119,13 +119,12 @@ export function main() {
|
||||
`Could not compile '${stringify(HelloRootDirectiveIsNotCmp)}' because it is not a component.`);
|
||||
expect(logger.res.join("")).toContain("Could not compile");
|
||||
async.done();
|
||||
return null;
|
||||
});
|
||||
}));
|
||||
|
||||
it('should throw if no element is found', inject([AsyncTestCompleter], (async) => {
|
||||
var logger = new _ArrayLogger();
|
||||
var exceptionHandler = new ExceptionHandler(logger, !IS_DART);
|
||||
var exceptionHandler = new ExceptionHandler(logger, false);
|
||||
|
||||
var refPromise =
|
||||
bootstrap(HelloRootCmp, [provide(ExceptionHandler, {useValue: exceptionHandler})]);
|
||||
@@ -137,10 +136,25 @@ export function main() {
|
||||
}));
|
||||
|
||||
if (DOM.supportsDOMEvents()) {
|
||||
it('should forward the error to promise when bootstrap fails',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
// Skip for dart since it causes a confusing error message in console when test passes.
|
||||
var logger = new _ArrayLogger();
|
||||
var exceptionHandler = new ExceptionHandler(logger, false);
|
||||
|
||||
var refPromise =
|
||||
bootstrap(HelloRootCmp, [provide(ExceptionHandler, {useValue: exceptionHandler})]);
|
||||
PromiseWrapper.then(refPromise, null, (reason: BaseException) => {
|
||||
expect(reason.message)
|
||||
.toContain('The selector "hello-app" did not match any elements');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should invoke the default exception handler when bootstrap fails',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
var logger = new _ArrayLogger();
|
||||
var exceptionHandler = new ExceptionHandler(logger, !IS_DART);
|
||||
var exceptionHandler = new ExceptionHandler(logger, false);
|
||||
|
||||
var refPromise =
|
||||
bootstrap(HelloRootCmp, [provide(ExceptionHandler, {useValue: exceptionHandler})]);
|
||||
|
||||
@@ -162,7 +162,6 @@ var NG_CORE = [
|
||||
'DirectiveResolver',
|
||||
'DynamicComponentLoader',
|
||||
'ElementRef',
|
||||
'ErrorHandlingFn:dart',
|
||||
'Output',
|
||||
'EmbeddedViewRef',
|
||||
'EventEmitter',
|
||||
@@ -244,7 +243,6 @@ var NG_CORE = [
|
||||
'ViewResolver',
|
||||
'WrappedException',
|
||||
'WrappedValue',
|
||||
'ZeroArgFunction:dart',
|
||||
'asNativeElements',
|
||||
'bind',
|
||||
'provide',
|
||||
|
||||
@@ -51,7 +51,7 @@ export function main() {
|
||||
el = DOM.createElement('app-cmp', fakeDoc);
|
||||
DOM.appendChild(fakeDoc.body, el);
|
||||
var logger = new _ArrayLogger();
|
||||
var exceptionHandler = new ExceptionHandler(logger, !IS_DART);
|
||||
var exceptionHandler = new ExceptionHandler(logger, false);
|
||||
testBindings = [
|
||||
ROUTER_PROVIDERS,
|
||||
provide(LocationStrategy, {useClass: MockLocationStrategy}),
|
||||
|
||||
@@ -23,9 +23,6 @@
|
||||
"selenium-webdriver/selenium-webdriver.d.ts": {
|
||||
"commit": "6eebd5e90a1cbd6b47b0705ba72dbcd5baf846f3"
|
||||
},
|
||||
"zone.js/zone.js.d.ts": {
|
||||
"commit": "6eebd5e90a1cbd6b47b0705ba72dbcd5baf846f3"
|
||||
},
|
||||
"angular-protractor/angular-protractor.d.ts": {
|
||||
"commit": "6eebd5e90a1cbd6b47b0705ba72dbcd5baf846f3"
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user