Skip to content

Commit

Permalink
build: upgrade zone.js
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion committed Apr 1, 2018
1 parent 43d6202 commit edebbe2
Show file tree
Hide file tree
Showing 26 changed files with 57 additions and 249 deletions.
6 changes: 1 addition & 5 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@ filegroup(
srcs = [
"//:node_modules/reflect-metadata/Reflect.js",
"//:node_modules/zone.js/dist/zone.js",
"//:node_modules/zone.js/dist/async-test.js",
"//:node_modules/zone.js/dist/sync-test.js",
"//:node_modules/zone.js/dist/fake-async-test.js",
"//:node_modules/zone.js/dist/zone-testing.js",
"//:node_modules/zone.js/dist/task-tracking.js",
"//:node_modules/zone.js/dist/proxy.js",
"//:node_modules/zone.js/dist/jasmine-patch.js",
],
)

Expand Down
7 changes: 1 addition & 6 deletions aio/content/examples/http/src/main-specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ declare var jasmine;

import './polyfills';

import 'zone.js/dist/async-test';
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 'zone.js/dist/zone-testing';

import { getTestBed } from '@angular/core/testing';
import {
Expand Down
7 changes: 1 addition & 6 deletions aio/content/examples/setup/src/quickstart-specs.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@
<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/long-stack-trace-zone.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 src="node_modules/zone.js/dist/zone-testing.js"></script>

<!-- #docregion files -->
<script>
Expand Down
7 changes: 1 addition & 6 deletions aio/content/examples/testing/src/main-specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ declare var jasmine;

import './polyfills';

import 'zone.js/dist/async-test';
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 'zone.js/dist/zone-testing';

import { getTestBed } from '@angular/core/testing';
import {
Expand Down
7 changes: 1 addition & 6 deletions aio/content/examples/testing/src/tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@
<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/long-stack-trace-zone.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 src="node_modules/zone.js/dist/zone-testing.js"></script>

<script>
var __spec_files__ = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ module.exports = function(config) {

// zone.js
'node_modules/zone.js/dist/zone.js',
'node_modules/zone.js/dist/long-stack-trace-zone.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',
'node_modules/zone.js/dist/zone-testing.js',

// RxJs.
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
Expand Down
7 changes: 1 addition & 6 deletions aio/content/examples/upgrade-phonecat-2-hybrid/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ module.exports = function(config) {

// zone.js
'node_modules/zone.js/dist/zone.js',
'node_modules/zone.js/dist/long-stack-trace-zone.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',
'node_modules/zone.js/dist/zone-testing.js',

// RxJs
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
Expand Down
7 changes: 1 addition & 6 deletions aio/content/examples/upgrade-phonecat-3-final/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ module.exports = function(config) {

// zone.js
'node_modules/zone.js/dist/zone.js',
'node_modules/zone.js/dist/long-stack-trace-zone.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',
'node_modules/zone.js/dist/zone-testing.js',

// RxJs
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
Expand Down
7 changes: 1 addition & 6 deletions aio/content/examples/webpack/config/karma-test-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ require('core-js/es6');
require('core-js/es7/reflect');

require('zone.js/dist/zone');
require('zone.js/dist/long-stack-trace-zone');
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');
require('zone.js/dist/zone-testing');

var appContext = require.context('../src', true, /\.spec\.ts/);

Expand Down
2 changes: 1 addition & 1 deletion aio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"rxjs-compat": "6.0.0-beta.4",
"tslib": "^1.9.0",
"web-animations-js": "^2.2.5",
"zone.js": "^0.8.19"
"zone.js": "^0.8.23"
},
"devDependencies": {
"@angular/cli": "^1.7.3",
Expand Down
4 changes: 2 additions & 2 deletions aio/scripts/_payload-limits.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"master": {
"uncompressed": {
"inline": 1971,
"main": 567849,
"polyfills": 40272,
"main": 567946,
"polyfills": 38939,
"prettify": 14886
}
}
Expand Down
8 changes: 5 additions & 3 deletions aio/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1107,19 +1107,21 @@ describe('AppComponent', () => {
checkHostClass('view', '');
});

it('should set the css class of the host container based on the open/closed state of the side nav', async () => {
it('should set the css class of the host container based on the open/closed state of the side nav', () => {
initializeTest(false);

navigateTo('guide/pipes');
checkHostClass('sidenav', 'open');

sidenav.close();
await waitForEmit(sidenav.onClose);
waitForEmit(sidenav.onClose);
jasmine.clock().tick(0);
fixture.detectChanges();
checkHostClass('sidenav', 'closed');

sidenav.open();
await waitForEmit(sidenav.onOpen);
waitForEmit(sidenav.onOpen);
jasmine.clock().tick(0);
fixture.detectChanges();
checkHostClass('sidenav', 'open');

Expand Down
7 changes: 1 addition & 6 deletions aio/src/test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
// 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/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 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
Expand Down
7 changes: 1 addition & 6 deletions aio/tools/examples/shared/boilerplate/cli/src/test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
// 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/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 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
Expand Down
6 changes: 3 additions & 3 deletions aio/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9827,6 +9827,6 @@ zip-stream@~0.6.0:
lodash "~3.10.1"
readable-stream "~1.0.26"

zone.js@^0.8.19:
version "0.8.19"
resolved "https://registry.yarnpkg.com/zone.js/-/zone.js-0.8.19.tgz#a4b522cd9e8b7b616a638c297d720d4c7f292f71"
zone.js@^0.8.23:
version "0.8.23"
resolved "https://registry.yarnpkg.com/zone.js/-/zone.js-0.8.23.tgz#7ab0bc9bedb4b9197864563841b4b478dd9bfce7"
2 changes: 1 addition & 1 deletion integration/_payload-limits.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"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": 257298,
"polyfills": 59483
"polyfills": 60187
}
}
},
Expand Down
7 changes: 1 addition & 6 deletions karma-js.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,8 @@ module.exports = function(config) {

'node_modules/core-js/client/core.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/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.
'test-events.js',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"reflect-metadata": "^0.1.3",
"rxjs": "6.0.0-beta.4",
"tslib": "^1.7.1",
"zone.js": "^0.8.12"
"zone.js": "^0.8.23"
},
"optionalDependencies": {
"fsevents": "1.1.2"
Expand Down
90 changes: 7 additions & 83 deletions packages/core/testing/src/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/

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
Expand All @@ -28,85 +24,13 @@ const _global = <any>(typeof window === 'undefined' ? global : window);
* @stable
*/
export function async(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);
}
});
const _Zone: any = typeof Zone !== 'undefined' ? Zone : null;
if (!_Zone) {
return function() {
return Promise.reject(
'Zone is needed for the async() test helper but could not be found. ' +
'Please make sure that your environment includes zone.js/dist/zone.js');
};
}
// 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);
return _Zone && _Zone[_Zone.__symbol__('asyncTest')](fn);
}

0 comments on commit edebbe2

Please sign in to comment.