parent
46eadb5cfb
commit
c560423b52
|
@ -40,12 +40,8 @@ filegroup(
|
||||||
srcs = [
|
srcs = [
|
||||||
"//:node_modules/reflect-metadata/Reflect.js",
|
"//:node_modules/reflect-metadata/Reflect.js",
|
||||||
"//:node_modules/zone.js/dist/zone.js",
|
"//:node_modules/zone.js/dist/zone.js",
|
||||||
"//:node_modules/zone.js/dist/async-test.js",
|
"//:node_modules/zone.js/dist/zone-testing.js",
|
||||||
"//:node_modules/zone.js/dist/sync-test.js",
|
|
||||||
"//:node_modules/zone.js/dist/fake-async-test.js",
|
|
||||||
"//:node_modules/zone.js/dist/task-tracking.js",
|
"//:node_modules/zone.js/dist/task-tracking.js",
|
||||||
"//:node_modules/zone.js/dist/proxy.js",
|
|
||||||
"//:node_modules/zone.js/dist/jasmine-patch.js",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,7 @@ declare var jasmine;
|
||||||
|
|
||||||
import './polyfills';
|
import './polyfills';
|
||||||
|
|
||||||
import 'zone.js/dist/async-test';
|
import 'zone.js/dist/zone-testing';
|
||||||
import 'zone.js/dist/fake-async-test';
|
|
||||||
import 'zone.js/dist/long-stack-trace-zone';
|
|
||||||
import 'zone.js/dist/proxy.js';
|
|
||||||
import 'zone.js/dist/sync-test';
|
|
||||||
import 'zone.js/dist/jasmine-patch';
|
|
||||||
|
|
||||||
import { getTestBed } from '@angular/core/testing';
|
import { getTestBed } from '@angular/core/testing';
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -21,12 +21,7 @@
|
||||||
<script src="node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
|
<script src="node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
|
||||||
|
|
||||||
<script src="node_modules/zone.js/dist/zone.js"></script>
|
<script src="node_modules/zone.js/dist/zone.js"></script>
|
||||||
<script src="node_modules/zone.js/dist/long-stack-trace-zone.js"></script>
|
<script src="node_modules/zone.js/dist/zone-testing.js"></script>
|
||||||
<script src="node_modules/zone.js/dist/proxy.js"></script>
|
|
||||||
<script src="node_modules/zone.js/dist/sync-test.js"></script>
|
|
||||||
<script src="node_modules/zone.js/dist/jasmine-patch.js"></script>
|
|
||||||
<script src="node_modules/zone.js/dist/async-test.js"></script>
|
|
||||||
<script src="node_modules/zone.js/dist/fake-async-test.js"></script>
|
|
||||||
|
|
||||||
<!-- #docregion files -->
|
<!-- #docregion files -->
|
||||||
<script>
|
<script>
|
||||||
|
|
|
@ -6,12 +6,7 @@ declare var jasmine;
|
||||||
|
|
||||||
import './polyfills';
|
import './polyfills';
|
||||||
|
|
||||||
import 'zone.js/dist/async-test';
|
import 'zone.js/dist/zone-testing';
|
||||||
import 'zone.js/dist/fake-async-test';
|
|
||||||
import 'zone.js/dist/long-stack-trace-zone';
|
|
||||||
import 'zone.js/dist/proxy.js';
|
|
||||||
import 'zone.js/dist/sync-test';
|
|
||||||
import 'zone.js/dist/jasmine-patch';
|
|
||||||
|
|
||||||
import { getTestBed } from '@angular/core/testing';
|
import { getTestBed } from '@angular/core/testing';
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -22,12 +22,7 @@
|
||||||
<script src="node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
|
<script src="node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
|
||||||
|
|
||||||
<script src="node_modules/zone.js/dist/zone.js"></script>
|
<script src="node_modules/zone.js/dist/zone.js"></script>
|
||||||
<script src="node_modules/zone.js/dist/long-stack-trace-zone.js"></script>
|
<script src="node_modules/zone.js/dist/zone-testing.js"></script>
|
||||||
<script src="node_modules/zone.js/dist/proxy.js"></script>
|
|
||||||
<script src="node_modules/zone.js/dist/sync-test.js"></script>
|
|
||||||
<script src="node_modules/zone.js/dist/jasmine-patch.js"></script>
|
|
||||||
<script src="node_modules/zone.js/dist/async-test.js"></script>
|
|
||||||
<script src="node_modules/zone.js/dist/fake-async-test.js"></script>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var __spec_files__ = [
|
var __spec_files__ = [
|
||||||
|
|
|
@ -22,12 +22,7 @@ module.exports = function(config) {
|
||||||
|
|
||||||
// zone.js
|
// zone.js
|
||||||
'node_modules/zone.js/dist/zone.js',
|
'node_modules/zone.js/dist/zone.js',
|
||||||
'node_modules/zone.js/dist/long-stack-trace-zone.js',
|
'node_modules/zone.js/dist/zone-testing.js',
|
||||||
'node_modules/zone.js/dist/proxy.js',
|
|
||||||
'node_modules/zone.js/dist/sync-test.js',
|
|
||||||
'node_modules/zone.js/dist/jasmine-patch.js',
|
|
||||||
'node_modules/zone.js/dist/async-test.js',
|
|
||||||
'node_modules/zone.js/dist/fake-async-test.js',
|
|
||||||
|
|
||||||
// RxJs.
|
// RxJs.
|
||||||
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
|
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
|
||||||
|
|
|
@ -41,12 +41,7 @@ module.exports = function(config) {
|
||||||
|
|
||||||
// zone.js
|
// zone.js
|
||||||
'node_modules/zone.js/dist/zone.js',
|
'node_modules/zone.js/dist/zone.js',
|
||||||
'node_modules/zone.js/dist/long-stack-trace-zone.js',
|
'node_modules/zone.js/dist/zone-testing.js',
|
||||||
'node_modules/zone.js/dist/proxy.js',
|
|
||||||
'node_modules/zone.js/dist/sync-test.js',
|
|
||||||
'node_modules/zone.js/dist/jasmine-patch.js',
|
|
||||||
'node_modules/zone.js/dist/async-test.js',
|
|
||||||
'node_modules/zone.js/dist/fake-async-test.js',
|
|
||||||
|
|
||||||
// RxJs
|
// RxJs
|
||||||
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
|
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
|
||||||
|
|
|
@ -41,12 +41,7 @@ module.exports = function(config) {
|
||||||
|
|
||||||
// zone.js
|
// zone.js
|
||||||
'node_modules/zone.js/dist/zone.js',
|
'node_modules/zone.js/dist/zone.js',
|
||||||
'node_modules/zone.js/dist/long-stack-trace-zone.js',
|
'node_modules/zone.js/dist/zone-testing.js',
|
||||||
'node_modules/zone.js/dist/proxy.js',
|
|
||||||
'node_modules/zone.js/dist/sync-test.js',
|
|
||||||
'node_modules/zone.js/dist/jasmine-patch.js',
|
|
||||||
'node_modules/zone.js/dist/async-test.js',
|
|
||||||
'node_modules/zone.js/dist/fake-async-test.js',
|
|
||||||
|
|
||||||
// RxJs
|
// RxJs
|
||||||
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
|
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
|
||||||
|
|
|
@ -5,12 +5,7 @@ require('core-js/es6');
|
||||||
require('core-js/es7/reflect');
|
require('core-js/es7/reflect');
|
||||||
|
|
||||||
require('zone.js/dist/zone');
|
require('zone.js/dist/zone');
|
||||||
require('zone.js/dist/long-stack-trace-zone');
|
require('zone.js/dist/zone-testing');
|
||||||
require('zone.js/dist/proxy');
|
|
||||||
require('zone.js/dist/sync-test');
|
|
||||||
require('zone.js/dist/jasmine-patch');
|
|
||||||
require('zone.js/dist/async-test');
|
|
||||||
require('zone.js/dist/fake-async-test');
|
|
||||||
|
|
||||||
var appContext = require.context('../src', true, /\.spec\.ts/);
|
var appContext = require.context('../src', true, /\.spec\.ts/);
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@
|
||||||
"rxjs-compat": "6.0.0-rc.0",
|
"rxjs-compat": "6.0.0-rc.0",
|
||||||
"tslib": "^1.9.0",
|
"tslib": "^1.9.0",
|
||||||
"web-animations-js": "^2.2.5",
|
"web-animations-js": "^2.2.5",
|
||||||
"zone.js": "^0.8.19"
|
"zone.js": "^0.8.25"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@angular/cli": "^1.7.3",
|
"@angular/cli": "^1.7.3",
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"uncompressed": {
|
"uncompressed": {
|
||||||
"inline": 1971,
|
"inline": 1971,
|
||||||
"main": 565539,
|
"main": 565539,
|
||||||
"polyfills": 40272,
|
"polyfills": 38514,
|
||||||
"prettify": 14886
|
"prettify": 14886
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
||||||
|
|
||||||
import 'zone.js/dist/long-stack-trace-zone';
|
import 'zone.js/dist/zone-testing';
|
||||||
import 'zone.js/dist/proxy.js';
|
|
||||||
import 'zone.js/dist/sync-test';
|
|
||||||
import 'zone.js/dist/jasmine-patch';
|
|
||||||
import 'zone.js/dist/async-test';
|
|
||||||
import 'zone.js/dist/fake-async-test';
|
|
||||||
import { getTestBed } from '@angular/core/testing';
|
import { getTestBed } from '@angular/core/testing';
|
||||||
import {
|
import {
|
||||||
BrowserDynamicTestingModule,
|
BrowserDynamicTestingModule,
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
||||||
|
|
||||||
import 'zone.js/dist/long-stack-trace-zone';
|
import 'zone.js/dist/zone-testing';
|
||||||
import 'zone.js/dist/proxy.js';
|
|
||||||
import 'zone.js/dist/sync-test';
|
|
||||||
import 'zone.js/dist/jasmine-patch';
|
|
||||||
import 'zone.js/dist/async-test';
|
|
||||||
import 'zone.js/dist/fake-async-test';
|
|
||||||
import { getTestBed } from '@angular/core/testing';
|
import { getTestBed } from '@angular/core/testing';
|
||||||
import {
|
import {
|
||||||
BrowserDynamicTestingModule,
|
BrowserDynamicTestingModule,
|
||||||
|
|
|
@ -9827,6 +9827,6 @@ zip-stream@~0.6.0:
|
||||||
lodash "~3.10.1"
|
lodash "~3.10.1"
|
||||||
readable-stream "~1.0.26"
|
readable-stream "~1.0.26"
|
||||||
|
|
||||||
zone.js@^0.8.19:
|
zone.js@^0.8.25:
|
||||||
version "0.8.19"
|
version "0.8.25"
|
||||||
resolved "https://registry.yarnpkg.com/zone.js/-/zone.js-0.8.19.tgz#a4b522cd9e8b7b616a638c297d720d4c7f292f71"
|
resolved "https://registry.yarnpkg.com/zone.js/-/zone.js-0.8.25.tgz#e20e5e85b881e2e66352612b5f238e8309e5badd"
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"inline": 1508,
|
"inline": 1508,
|
||||||
"main": "TODO(i): temporarily increase the payload size limit to 257298 from 155112, we need CLI v6 to bring the size down",
|
"main": "TODO(i): temporarily increase the payload size limit to 257298 from 155112, we need CLI v6 to bring the size down",
|
||||||
"main": 257298,
|
"main": 257298,
|
||||||
"polyfills": 59483
|
"polyfills": 60187
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -29,13 +29,8 @@ module.exports = function(config) {
|
||||||
|
|
||||||
'node_modules/core-js/client/core.js',
|
'node_modules/core-js/client/core.js',
|
||||||
'node_modules/zone.js/dist/zone.js',
|
'node_modules/zone.js/dist/zone.js',
|
||||||
'node_modules/zone.js/dist/long-stack-trace-zone.js',
|
'node_modules/zone.js/dist/zone-testing.js',
|
||||||
'node_modules/zone.js/dist/task-tracking.js',
|
'node_modules/zone.js/dist/task-tracking.js',
|
||||||
'node_modules/zone.js/dist/proxy.js',
|
|
||||||
'node_modules/zone.js/dist/sync-test.js',
|
|
||||||
'node_modules/zone.js/dist/jasmine-patch.js',
|
|
||||||
'node_modules/zone.js/dist/async-test.js',
|
|
||||||
'node_modules/zone.js/dist/fake-async-test.js',
|
|
||||||
|
|
||||||
// Including systemjs because it defines `__eval`, which produces correct stack traces.
|
// Including systemjs because it defines `__eval`, which produces correct stack traces.
|
||||||
'test-events.js',
|
'test-events.js',
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
"reflect-metadata": "^0.1.3",
|
"reflect-metadata": "^0.1.3",
|
||||||
"rxjs": "6.0.0-rc.0",
|
"rxjs": "6.0.0-rc.0",
|
||||||
"tslib": "^1.7.1",
|
"tslib": "^1.7.1",
|
||||||
"zone.js": "^0.8.12"
|
"zone.js": "^0.8.25"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"fsevents": "1.1.2"
|
"fsevents": "1.1.2"
|
||||||
|
|
|
@ -6,9 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare var global: any;
|
import {asyncFallback} from './async_fallback';
|
||||||
|
|
||||||
const _global = <any>(typeof window === 'undefined' ? global : window);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps a test function in an asynchronous test zone. The test will automatically
|
* Wraps a test function in an asynchronous test zone. The test will automatically
|
||||||
|
@ -28,85 +26,20 @@ const _global = <any>(typeof window === 'undefined' ? global : window);
|
||||||
* @stable
|
* @stable
|
||||||
*/
|
*/
|
||||||
export function async(fn: Function): (done: any) => any {
|
export function async(fn: Function): (done: any) => any {
|
||||||
// If we're running using the Jasmine test framework, adapt to call the 'done'
|
const _Zone: any = typeof Zone !== 'undefined' ? Zone : null;
|
||||||
// function when asynchronous activity is finished.
|
if (!_Zone) {
|
||||||
if (_global.jasmine) {
|
return function() {
|
||||||
// Not using an arrow function to preserve context passed from call site
|
return Promise.reject(
|
||||||
return function(done: any) {
|
'Zone is needed for the async() test helper but could not be found. ' +
|
||||||
if (!done) {
|
'Please make sure that your environment includes zone.js/dist/zone.js');
|
||||||
// if we run beforeEach in @angular/core/testing/testing_internal then we get no done
|
|
||||||
// fake it here and assume sync.
|
|
||||||
done = function() {};
|
|
||||||
done.fail = function(e: any) { throw e; };
|
|
||||||
}
|
|
||||||
runInTestZone(fn, this, done, (err: any) => {
|
|
||||||
if (typeof err === 'string') {
|
|
||||||
return done.fail(new Error(<string>err));
|
|
||||||
} else {
|
|
||||||
done.fail(err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// Otherwise, return a promise which will resolve when asynchronous activity
|
const asyncTest = _Zone && _Zone[_Zone.__symbol__('asyncTest')];
|
||||||
// is finished. This will be correctly consumed by the Mocha framework with
|
if (typeof asyncTest === 'function') {
|
||||||
// it('...', async(myFn)); or can be used in a custom framework.
|
return asyncTest(fn);
|
||||||
// Not using an arrow function to preserve context passed from call site
|
|
||||||
return function() {
|
|
||||||
return new Promise<void>((finishCallback, failCallback) => {
|
|
||||||
runInTestZone(fn, this, finishCallback, failCallback);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function runInTestZone(
|
|
||||||
fn: Function, context: any, finishCallback: Function, failCallback: Function) {
|
|
||||||
const currentZone = Zone.current;
|
|
||||||
const AsyncTestZoneSpec = (Zone as any)['AsyncTestZoneSpec'];
|
|
||||||
if (AsyncTestZoneSpec === undefined) {
|
|
||||||
throw new Error(
|
|
||||||
'AsyncTestZoneSpec is needed for the async() test helper but could not be found. ' +
|
|
||||||
'Please make sure that your environment includes zone.js/dist/async-test.js');
|
|
||||||
}
|
}
|
||||||
const ProxyZoneSpec = (Zone as any)['ProxyZoneSpec'] as {
|
// not using new version of zone.js
|
||||||
get(): {setDelegate(spec: ZoneSpec): void; getDelegate(): ZoneSpec;};
|
// TODO @JiaLiPassion, remove this after all library updated to
|
||||||
assertPresent: () => void;
|
// newest version of zone.js(0.8.25)
|
||||||
};
|
return asyncFallback(fn);
|
||||||
if (ProxyZoneSpec === undefined) {
|
|
||||||
throw new Error(
|
|
||||||
'ProxyZoneSpec is needed for the async() test helper but could not be found. ' +
|
|
||||||
'Please make sure that your environment includes zone.js/dist/proxy.js');
|
|
||||||
}
|
|
||||||
const proxyZoneSpec = ProxyZoneSpec.get();
|
|
||||||
ProxyZoneSpec.assertPresent();
|
|
||||||
// We need to create the AsyncTestZoneSpec outside the ProxyZone.
|
|
||||||
// If we do it in ProxyZone then we will get to infinite recursion.
|
|
||||||
const proxyZone = Zone.current.getZoneWith('ProxyZoneSpec');
|
|
||||||
const previousDelegate = proxyZoneSpec.getDelegate();
|
|
||||||
proxyZone.parent.run(() => {
|
|
||||||
const testZoneSpec: ZoneSpec = new AsyncTestZoneSpec(
|
|
||||||
() => {
|
|
||||||
// Need to restore the original zone.
|
|
||||||
currentZone.run(() => {
|
|
||||||
if (proxyZoneSpec.getDelegate() == testZoneSpec) {
|
|
||||||
// Only reset the zone spec if it's sill this one. Otherwise, assume it's OK.
|
|
||||||
proxyZoneSpec.setDelegate(previousDelegate);
|
|
||||||
}
|
|
||||||
finishCallback();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
(error: any) => {
|
|
||||||
// Need to restore the original zone.
|
|
||||||
currentZone.run(() => {
|
|
||||||
if (proxyZoneSpec.getDelegate() == testZoneSpec) {
|
|
||||||
// Only reset the zone spec if it's sill this one. Otherwise, assume it's OK.
|
|
||||||
proxyZoneSpec.setDelegate(previousDelegate);
|
|
||||||
}
|
|
||||||
failCallback(error);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
'test');
|
|
||||||
proxyZoneSpec.setDelegate(testZoneSpec);
|
|
||||||
});
|
|
||||||
return Zone.current.runGuarded(fn, context);
|
|
||||||
}
|
}
|
|
@ -0,0 +1,116 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright Google Inc. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by an MIT-style license that can be
|
||||||
|
* found in the LICENSE file at https://angular.io/license
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* async has been moved to zone.js
|
||||||
|
* this file is for fallback in case old version of zone.js is used
|
||||||
|
*/
|
||||||
|
declare var global: any;
|
||||||
|
|
||||||
|
const _global = <any>(typeof window === 'undefined' ? global : window);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps a test function in an asynchronous test zone. The test will automatically
|
||||||
|
* complete when all asynchronous calls within this zone are done. Can be used
|
||||||
|
* to wrap an {@link inject} call.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* it('...', async(inject([AClass], (object) => {
|
||||||
|
* object.doSomething.then(() => {
|
||||||
|
* expect(...);
|
||||||
|
* })
|
||||||
|
* });
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @stable
|
||||||
|
*/
|
||||||
|
export function asyncFallback(fn: Function): (done: any) => any {
|
||||||
|
// If we're running using the Jasmine test framework, adapt to call the 'done'
|
||||||
|
// function when asynchronous activity is finished.
|
||||||
|
if (_global.jasmine) {
|
||||||
|
// Not using an arrow function to preserve context passed from call site
|
||||||
|
return function(done: any) {
|
||||||
|
if (!done) {
|
||||||
|
// if we run beforeEach in @angular/core/testing/testing_internal then we get no done
|
||||||
|
// fake it here and assume sync.
|
||||||
|
done = function() {};
|
||||||
|
done.fail = function(e: any) { throw e; };
|
||||||
|
}
|
||||||
|
runInTestZone(fn, this, done, (err: any) => {
|
||||||
|
if (typeof err === 'string') {
|
||||||
|
return done.fail(new Error(<string>err));
|
||||||
|
} else {
|
||||||
|
done.fail(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// Otherwise, return a promise which will resolve when asynchronous activity
|
||||||
|
// is finished. This will be correctly consumed by the Mocha framework with
|
||||||
|
// it('...', async(myFn)); or can be used in a custom framework.
|
||||||
|
// Not using an arrow function to preserve context passed from call site
|
||||||
|
return function() {
|
||||||
|
return new Promise<void>((finishCallback, failCallback) => {
|
||||||
|
runInTestZone(fn, this, finishCallback, failCallback);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function runInTestZone(
|
||||||
|
fn: Function, context: any, finishCallback: Function, failCallback: Function) {
|
||||||
|
const currentZone = Zone.current;
|
||||||
|
const AsyncTestZoneSpec = (Zone as any)['AsyncTestZoneSpec'];
|
||||||
|
if (AsyncTestZoneSpec === undefined) {
|
||||||
|
throw new Error(
|
||||||
|
'AsyncTestZoneSpec is needed for the async() test helper but could not be found. ' +
|
||||||
|
'Please make sure that your environment includes zone.js/dist/async-test.js');
|
||||||
|
}
|
||||||
|
const ProxyZoneSpec = (Zone as any)['ProxyZoneSpec'] as {
|
||||||
|
get(): {setDelegate(spec: ZoneSpec): void; getDelegate(): ZoneSpec;};
|
||||||
|
assertPresent: () => void;
|
||||||
|
};
|
||||||
|
if (ProxyZoneSpec === undefined) {
|
||||||
|
throw new Error(
|
||||||
|
'ProxyZoneSpec is needed for the async() test helper but could not be found. ' +
|
||||||
|
'Please make sure that your environment includes zone.js/dist/proxy.js');
|
||||||
|
}
|
||||||
|
const proxyZoneSpec = ProxyZoneSpec.get();
|
||||||
|
ProxyZoneSpec.assertPresent();
|
||||||
|
// We need to create the AsyncTestZoneSpec outside the ProxyZone.
|
||||||
|
// If we do it in ProxyZone then we will get to infinite recursion.
|
||||||
|
const proxyZone = Zone.current.getZoneWith('ProxyZoneSpec');
|
||||||
|
const previousDelegate = proxyZoneSpec.getDelegate();
|
||||||
|
proxyZone.parent.run(() => {
|
||||||
|
const testZoneSpec: ZoneSpec = new AsyncTestZoneSpec(
|
||||||
|
() => {
|
||||||
|
// Need to restore the original zone.
|
||||||
|
currentZone.run(() => {
|
||||||
|
if (proxyZoneSpec.getDelegate() == testZoneSpec) {
|
||||||
|
// Only reset the zone spec if it's sill this one. Otherwise, assume it's OK.
|
||||||
|
proxyZoneSpec.setDelegate(previousDelegate);
|
||||||
|
}
|
||||||
|
finishCallback();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
(error: any) => {
|
||||||
|
// Need to restore the original zone.
|
||||||
|
currentZone.run(() => {
|
||||||
|
if (proxyZoneSpec.getDelegate() == testZoneSpec) {
|
||||||
|
// Only reset the zone spec if it's sill this one. Otherwise, assume it's OK.
|
||||||
|
proxyZoneSpec.setDelegate(previousDelegate);
|
||||||
|
}
|
||||||
|
failCallback(error);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
'test');
|
||||||
|
proxyZoneSpec.setDelegate(testZoneSpec);
|
||||||
|
});
|
||||||
|
return Zone.current.runGuarded(fn, context);
|
||||||
|
}
|
|
@ -5,17 +5,10 @@
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
* Use of this source code is governed by an MIT-style license that can be
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
import {discardPeriodicTasksFallback, fakeAsyncFallback, flushFallback, flushMicrotasksFallback, resetFakeAsyncZoneFallback, tickFallback} from './fake_async_fallback';
|
||||||
|
|
||||||
const _Zone: any = typeof Zone !== 'undefined' ? Zone : null;
|
const _Zone: any = typeof Zone !== 'undefined' ? Zone : null;
|
||||||
const FakeAsyncTestZoneSpec = _Zone && _Zone['FakeAsyncTestZoneSpec'];
|
const fakeAsyncTestModule = _Zone && _Zone[_Zone.__symbol__('fakeAsyncTest')];
|
||||||
type ProxyZoneSpec = {
|
|
||||||
setDelegate(delegateSpec: ZoneSpec): void; getDelegate(): ZoneSpec; resetDelegate(): void;
|
|
||||||
};
|
|
||||||
const ProxyZoneSpec: {get(): ProxyZoneSpec; assertPresent: () => ProxyZoneSpec} =
|
|
||||||
_Zone && _Zone['ProxyZoneSpec'];
|
|
||||||
|
|
||||||
let _fakeAsyncTestZoneSpec: any = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears out the shared fake async zone for a test.
|
* Clears out the shared fake async zone for a test.
|
||||||
|
@ -23,14 +16,14 @@ let _fakeAsyncTestZoneSpec: any = null;
|
||||||
*
|
*
|
||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
export function resetFakeAsyncZone() {
|
export function resetFakeAsyncZone(): void {
|
||||||
_fakeAsyncTestZoneSpec = null;
|
if (fakeAsyncTestModule) {
|
||||||
// in node.js testing we may not have ProxyZoneSpec in which case there is nothing to reset.
|
return fakeAsyncTestModule.resetFakeAsyncZone();
|
||||||
ProxyZoneSpec && ProxyZoneSpec.assertPresent().resetDelegate();
|
} else {
|
||||||
|
return resetFakeAsyncZoneFallback();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let _inFakeAsyncCall = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps a function to be executed in the fakeAsync zone:
|
* Wraps a function to be executed in the fakeAsync zone:
|
||||||
* - microtasks are manually executed by calling `flushMicrotasks()`,
|
* - microtasks are manually executed by calling `flushMicrotasks()`,
|
||||||
|
@ -50,55 +43,11 @@ let _inFakeAsyncCall = false;
|
||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
export function fakeAsync(fn: Function): (...args: any[]) => any {
|
export function fakeAsync(fn: Function): (...args: any[]) => any {
|
||||||
// Not using an arrow function to preserve context passed from call site
|
if (fakeAsyncTestModule) {
|
||||||
return function(...args: any[]) {
|
return fakeAsyncTestModule.fakeAsync(fn);
|
||||||
const proxyZoneSpec = ProxyZoneSpec.assertPresent();
|
} else {
|
||||||
if (_inFakeAsyncCall) {
|
return fakeAsyncFallback(fn);
|
||||||
throw new Error('fakeAsync() calls can not be nested');
|
|
||||||
}
|
|
||||||
_inFakeAsyncCall = true;
|
|
||||||
try {
|
|
||||||
if (!_fakeAsyncTestZoneSpec) {
|
|
||||||
if (proxyZoneSpec.getDelegate() instanceof FakeAsyncTestZoneSpec) {
|
|
||||||
throw new Error('fakeAsync() calls can not be nested');
|
|
||||||
}
|
|
||||||
|
|
||||||
_fakeAsyncTestZoneSpec = new FakeAsyncTestZoneSpec();
|
|
||||||
}
|
|
||||||
|
|
||||||
let res: any;
|
|
||||||
const lastProxyZoneSpec = proxyZoneSpec.getDelegate();
|
|
||||||
proxyZoneSpec.setDelegate(_fakeAsyncTestZoneSpec);
|
|
||||||
try {
|
|
||||||
res = fn.apply(this, args);
|
|
||||||
flushMicrotasks();
|
|
||||||
} finally {
|
|
||||||
proxyZoneSpec.setDelegate(lastProxyZoneSpec);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_fakeAsyncTestZoneSpec.pendingPeriodicTimers.length > 0) {
|
|
||||||
throw new Error(
|
|
||||||
`${_fakeAsyncTestZoneSpec.pendingPeriodicTimers.length} ` +
|
|
||||||
`periodic timer(s) still in the queue.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_fakeAsyncTestZoneSpec.pendingTimers.length > 0) {
|
|
||||||
throw new Error(
|
|
||||||
`${_fakeAsyncTestZoneSpec.pendingTimers.length} timer(s) still in the queue.`);
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
} finally {
|
|
||||||
_inFakeAsyncCall = false;
|
|
||||||
resetFakeAsyncZone();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function _getFakeAsyncZoneSpec(): any {
|
|
||||||
if (_fakeAsyncTestZoneSpec == null) {
|
|
||||||
throw new Error('The code should be running in the fakeAsync zone to call this function');
|
|
||||||
}
|
}
|
||||||
return _fakeAsyncTestZoneSpec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -114,7 +63,11 @@ function _getFakeAsyncZoneSpec(): any {
|
||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
export function tick(millis: number = 0): void {
|
export function tick(millis: number = 0): void {
|
||||||
_getFakeAsyncZoneSpec().tick(millis);
|
if (fakeAsyncTestModule) {
|
||||||
|
return fakeAsyncTestModule.tick(millis);
|
||||||
|
} else {
|
||||||
|
return tickFallback(millis);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -128,7 +81,11 @@ export function tick(millis: number = 0): void {
|
||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
export function flush(maxTurns?: number): number {
|
export function flush(maxTurns?: number): number {
|
||||||
return _getFakeAsyncZoneSpec().flush(maxTurns);
|
if (fakeAsyncTestModule) {
|
||||||
|
return fakeAsyncTestModule.flush(maxTurns);
|
||||||
|
} else {
|
||||||
|
return flushFallback(maxTurns);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,9 +94,11 @@ export function flush(maxTurns?: number): number {
|
||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
export function discardPeriodicTasks(): void {
|
export function discardPeriodicTasks(): void {
|
||||||
const zoneSpec = _getFakeAsyncZoneSpec();
|
if (fakeAsyncTestModule) {
|
||||||
const pendingTimers = zoneSpec.pendingPeriodicTimers;
|
return fakeAsyncTestModule.discardPeriodicTasks();
|
||||||
zoneSpec.pendingPeriodicTimers.length = 0;
|
} else {
|
||||||
|
discardPeriodicTasksFallback();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -148,5 +107,9 @@ export function discardPeriodicTasks(): void {
|
||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
export function flushMicrotasks(): void {
|
export function flushMicrotasks(): void {
|
||||||
_getFakeAsyncZoneSpec().flushMicrotasks();
|
if (fakeAsyncTestModule) {
|
||||||
|
return fakeAsyncTestModule.flushMicrotasks();
|
||||||
|
} else {
|
||||||
|
return flushMicrotasksFallback();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,155 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright Google Inc. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by an MIT-style license that can be
|
||||||
|
* found in the LICENSE file at https://angular.io/license
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fakeAsync has been moved to zone.js
|
||||||
|
* this file is for fallback in case old version of zone.js is used
|
||||||
|
*/
|
||||||
|
const _Zone: any = typeof Zone !== 'undefined' ? Zone : null;
|
||||||
|
const FakeAsyncTestZoneSpec = _Zone && _Zone['FakeAsyncTestZoneSpec'];
|
||||||
|
type ProxyZoneSpec = {
|
||||||
|
setDelegate(delegateSpec: ZoneSpec): void; getDelegate(): ZoneSpec; resetDelegate(): void;
|
||||||
|
};
|
||||||
|
const ProxyZoneSpec: {get(): ProxyZoneSpec; assertPresent: () => ProxyZoneSpec} =
|
||||||
|
_Zone && _Zone['ProxyZoneSpec'];
|
||||||
|
|
||||||
|
let _fakeAsyncTestZoneSpec: any = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears out the shared fake async zone for a test.
|
||||||
|
* To be called in a global `beforeEach`.
|
||||||
|
*
|
||||||
|
* @experimental
|
||||||
|
*/
|
||||||
|
export function resetFakeAsyncZoneFallback() {
|
||||||
|
_fakeAsyncTestZoneSpec = null;
|
||||||
|
// in node.js testing we may not have ProxyZoneSpec in which case there is nothing to reset.
|
||||||
|
ProxyZoneSpec && ProxyZoneSpec.assertPresent().resetDelegate();
|
||||||
|
}
|
||||||
|
|
||||||
|
let _inFakeAsyncCall = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps a function to be executed in the fakeAsync zone:
|
||||||
|
* - microtasks are manually executed by calling `flushMicrotasks()`,
|
||||||
|
* - timers are synchronous, `tick()` simulates the asynchronous passage of time.
|
||||||
|
*
|
||||||
|
* If there are any pending timers at the end of the function, an exception will be thrown.
|
||||||
|
*
|
||||||
|
* Can be used to wrap inject() calls.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* {@example core/testing/ts/fake_async.ts region='basic'}
|
||||||
|
*
|
||||||
|
* @param fn
|
||||||
|
* @returns The function wrapped to be executed in the fakeAsync zone
|
||||||
|
*
|
||||||
|
* @experimental
|
||||||
|
*/
|
||||||
|
export function fakeAsyncFallback(fn: Function): (...args: any[]) => any {
|
||||||
|
// Not using an arrow function to preserve context passed from call site
|
||||||
|
return function(...args: any[]) {
|
||||||
|
const proxyZoneSpec = ProxyZoneSpec.assertPresent();
|
||||||
|
if (_inFakeAsyncCall) {
|
||||||
|
throw new Error('fakeAsync() calls can not be nested');
|
||||||
|
}
|
||||||
|
_inFakeAsyncCall = true;
|
||||||
|
try {
|
||||||
|
if (!_fakeAsyncTestZoneSpec) {
|
||||||
|
if (proxyZoneSpec.getDelegate() instanceof FakeAsyncTestZoneSpec) {
|
||||||
|
throw new Error('fakeAsync() calls can not be nested');
|
||||||
|
}
|
||||||
|
|
||||||
|
_fakeAsyncTestZoneSpec = new FakeAsyncTestZoneSpec();
|
||||||
|
}
|
||||||
|
|
||||||
|
let res: any;
|
||||||
|
const lastProxyZoneSpec = proxyZoneSpec.getDelegate();
|
||||||
|
proxyZoneSpec.setDelegate(_fakeAsyncTestZoneSpec);
|
||||||
|
try {
|
||||||
|
res = fn.apply(this, args);
|
||||||
|
flushMicrotasksFallback();
|
||||||
|
} finally {
|
||||||
|
proxyZoneSpec.setDelegate(lastProxyZoneSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_fakeAsyncTestZoneSpec.pendingPeriodicTimers.length > 0) {
|
||||||
|
throw new Error(
|
||||||
|
`${_fakeAsyncTestZoneSpec.pendingPeriodicTimers.length} ` +
|
||||||
|
`periodic timer(s) still in the queue.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_fakeAsyncTestZoneSpec.pendingTimers.length > 0) {
|
||||||
|
throw new Error(
|
||||||
|
`${_fakeAsyncTestZoneSpec.pendingTimers.length} timer(s) still in the queue.`);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
} finally {
|
||||||
|
_inFakeAsyncCall = false;
|
||||||
|
resetFakeAsyncZoneFallback();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function _getFakeAsyncZoneSpec(): any {
|
||||||
|
if (_fakeAsyncTestZoneSpec == null) {
|
||||||
|
throw new Error('The code should be running in the fakeAsync zone to call this function');
|
||||||
|
}
|
||||||
|
return _fakeAsyncTestZoneSpec;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simulates the asynchronous passage of time for the timers in the fakeAsync zone.
|
||||||
|
*
|
||||||
|
* The microtasks queue is drained at the very start of this function and after any timer callback
|
||||||
|
* has been executed.
|
||||||
|
*
|
||||||
|
* ## Example
|
||||||
|
*
|
||||||
|
* {@example core/testing/ts/fake_async.ts region='basic'}
|
||||||
|
*
|
||||||
|
* @experimental
|
||||||
|
*/
|
||||||
|
export function tickFallback(millis: number = 0): void {
|
||||||
|
_getFakeAsyncZoneSpec().tick(millis);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simulates the asynchronous passage of time for the timers in the fakeAsync zone by
|
||||||
|
* draining the macrotask queue until it is empty. The returned value is the milliseconds
|
||||||
|
* of time that would have been elapsed.
|
||||||
|
*
|
||||||
|
* @param maxTurns
|
||||||
|
* @returns The simulated time elapsed, in millis.
|
||||||
|
*
|
||||||
|
* @experimental
|
||||||
|
*/
|
||||||
|
export function flushFallback(maxTurns?: number): number {
|
||||||
|
return _getFakeAsyncZoneSpec().flush(maxTurns);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discard all remaining periodic tasks.
|
||||||
|
*
|
||||||
|
* @experimental
|
||||||
|
*/
|
||||||
|
export function discardPeriodicTasksFallback(): void {
|
||||||
|
const zoneSpec = _getFakeAsyncZoneSpec();
|
||||||
|
const pendingTimers = zoneSpec.pendingPeriodicTimers;
|
||||||
|
zoneSpec.pendingPeriodicTimers.length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flush any pending microtasks.
|
||||||
|
*
|
||||||
|
* @experimental
|
||||||
|
*/
|
||||||
|
export function flushMicrotasksFallback(): void {
|
||||||
|
_getFakeAsyncZoneSpec().flushMicrotasks();
|
||||||
|
}
|
|
@ -27,11 +27,7 @@ filegroup(
|
||||||
"//:node_modules/@webcomponents/custom-elements/src/native-shim.js",
|
"//:node_modules/@webcomponents/custom-elements/src/native-shim.js",
|
||||||
"//:node_modules/reflect-metadata/Reflect.js",
|
"//:node_modules/reflect-metadata/Reflect.js",
|
||||||
"//:node_modules/zone.js/dist/zone.js",
|
"//:node_modules/zone.js/dist/zone.js",
|
||||||
"//:node_modules/zone.js/dist/async-test.js",
|
"//:node_modules/zone.js/dist/zone-testing.js",
|
||||||
"//:node_modules/zone.js/dist/sync-test.js",
|
|
||||||
"//:node_modules/zone.js/dist/fake-async-test.js",
|
|
||||||
"//:node_modules/zone.js/dist/proxy.js",
|
|
||||||
"//:node_modules/zone.js/dist/jasmine-patch.js",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -28,12 +28,7 @@ module.exports = function(config) {
|
||||||
|
|
||||||
// Zone.js dependencies
|
// Zone.js dependencies
|
||||||
'node_modules/zone.js/dist/zone.js',
|
'node_modules/zone.js/dist/zone.js',
|
||||||
'node_modules/zone.js/dist/long-stack-trace-zone.js',
|
'node_modules/zone.js/dist/zone-testing.js',
|
||||||
'node_modules/zone.js/dist/proxy.js',
|
|
||||||
'node_modules/zone.js/dist/sync-test.js',
|
|
||||||
'node_modules/zone.js/dist/jasmine-patch.js',
|
|
||||||
'node_modules/zone.js/dist/async-test.js',
|
|
||||||
'node_modules/zone.js/dist/fake-async-test.js',
|
|
||||||
|
|
||||||
{pattern: 'node_modules/rxjs/**/*', included: false, watched: false},
|
{pattern: 'node_modules/rxjs/**/*', included: false, watched: false},
|
||||||
|
|
||||||
|
|
|
@ -6475,6 +6475,6 @@ zip-stream@~0.5.0:
|
||||||
lodash "~3.2.0"
|
lodash "~3.2.0"
|
||||||
readable-stream "~1.0.26"
|
readable-stream "~1.0.26"
|
||||||
|
|
||||||
zone.js@^0.8.12:
|
zone.js@^0.8.25:
|
||||||
version "0.8.20"
|
version "0.8.25"
|
||||||
resolved "https://registry.yarnpkg.com/zone.js/-/zone.js-0.8.20.tgz#a218c48db09464b19ff6fc8f0d4bb5b1046e185d"
|
resolved "https://registry.yarnpkg.com/zone.js/-/zone.js-0.8.25.tgz#e20e5e85b881e2e66352612b5f238e8309e5badd"
|
||||||
|
|
Loading…
Reference in New Issue