Socket
Socket
Sign inDemoInstall

zone.js

Package Overview
Dependencies
Maintainers
2
Versions
124
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zone.js - npm Package Compare versions

Comparing version 0.6.13 to 0.6.14

dist/task-tracking.js

123

dist/jasmine-patch.js

@@ -48,30 +48,101 @@ /******/ (function(modules) { // webpackBootstrap

'use strict';
// Patch jasmine's it and fit functions so that the `done` wrapCallback always resets the zone
// to the jasmine zone, which should be the root zone. (angular/zone.js#91)
if (!Zone) {
throw new Error('zone.js does not seem to be installed');
}
// When you have in async test (test with `done` argument) jasmine will
// execute the next test synchronously in the done handler. This makes sense
// for most tests, but now with zones. With zones running next test
// synchronously means that the current zone does not get cleared. This
// results in a chain of nested zones, which makes it hard to reason about
// it. We override the `clearStack` method which forces jasmine to always
// drain the stack before next test gets executed.
jasmine.QueueRunner = (function (SuperQueueRunner) {
var originalZone = Zone.current;
// Subclass the `QueueRunner` and override the `clearStack` method.
function alwaysClearStack(fn) {
var zone = Zone.current.getZoneWith('JasmineClearStackZone')
|| Zone.current.getZoneWith('ProxyZoneSpec')
|| originalZone;
zone.scheduleMicroTask('jasmineCleanStack', fn);
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
(function () {
// Patch jasmine's describe/it/beforeEach/afterEach functions so test code always runs
// in a testZone (ProxyZone). (See: angular/zone.js#91 & angular/angular#10503)
if (!Zone)
throw new Error("Missing: zone.js");
if (!jasmine)
throw new Error("Missing: jasmine.js");
if (jasmine['__zone_patch__'])
throw new Error("'jasmine' has already been patched with 'Zone'.");
jasmine['__zone_patch__'] = true;
var SyncTestZoneSpec = Zone['SyncTestZoneSpec'];
var ProxyZoneSpec = Zone['ProxyZoneSpec'];
if (!SyncTestZoneSpec)
throw new Error("Missing: SyncTestZoneSpec");
if (!ProxyZoneSpec)
throw new Error("Missing: ProxyZoneSpec");
var ambientZone = Zone.current;
// Create a synchronous-only zone in which to run `describe` blocks in order to raise an
// error if any asynchronous operations are attempted inside of a `describe` but outside of
// a `beforeEach` or `it`.
var syncZone = ambientZone.fork(new SyncTestZoneSpec('jasmine.describe'));
// This is the zone which will be used for running individual tests.
// It will be a proxy zone, so that the tests function can retroactively install
// different zones.
// Example:
// - In beforeEach() do childZone = Zone.current.fork(...);
// - In it() try to do fakeAsync(). The issue is that because the beforeEach forked the
// zone outside of fakeAsync it will be able to escope the fakeAsync rules.
// - Because ProxyZone is parent fo `childZone` fakeAsync can retroactively add
// fakeAsync behavior to the childZone.
var testProxyZone = null;
// Monkey patch all of the jasmine DSL so that each function runs in appropriate zone.
var jasmineEnv = jasmine.getEnv();
['desribe', 'xdescribe', 'fdescribe'].forEach(function (methodName) {
var originalJasmineFn = jasmineEnv[methodName];
jasmineEnv[methodName] = function (description, specDefinitions) {
return originalJasmineFn.call(this, description, wrapDescribeInZone(specDefinitions));
};
});
['it', 'xit', 'fit'].forEach(function (methodName) {
var originalJasmineFn = jasmineEnv[methodName];
jasmineEnv[methodName] = function (description, specDefinitions) {
return originalJasmineFn.call(this, description, wrapTestInZone(specDefinitions));
};
});
['beforeEach', 'afterEach'].forEach(function (methodName) {
var originalJasmineFn = jasmineEnv[methodName];
jasmineEnv[methodName] = function (specDefinitions) {
return originalJasmineFn.call(this, wrapTestInZone(specDefinitions));
};
});
/**
* Gets a function wrapping the body of a Jasmine `describe` block to execute in a
* synchronous-only zone.
*/
function wrapDescribeInZone(describeBody) {
return function () {
return syncZone.run(describeBody, this, arguments);
};
}
function QueueRunner(options) {
options.clearStack = alwaysClearStack;
SuperQueueRunner.call(this, options);
/**
* Gets a function wrapping the body of a Jasmine `it/beforeEach/afterEach` block to
* execute in a ProxyZone zone.
* This will run in `testProxyZone`. The `testProxyZone` will be reset by the `ZoneQueueRunner`
*/
function wrapTestInZone(testBody) {
// The `done` callback is only passed through if the function expects at least one argument.
// Note we have to make a function with correct number of arguments, otherwise jasmine will
// think that all functions are sync or async.
return (testBody.length == 0)
? function () { return testProxyZone.run(testBody, this); }
: function (done) { return testProxyZone.run(testBody, this, [done]); };
}
QueueRunner.prototype = SuperQueueRunner.prototype;
return QueueRunner;
})(jasmine.QueueRunner);
var QueueRunner = jasmine.QueueRunner;
jasmine.QueueRunner = (function (_super) {
__extends(ZoneQueueRunner, _super);
function ZoneQueueRunner(attrs) {
attrs.clearStack = function (fn) { return fn(); }; // Don't clear since onComplete will clear.
attrs.onComplete = (function (fn) { return function () {
// All functions are done, clear the test zone.
testProxyZone = null;
ambientZone.scheduleMicroTask('jasmine.onComplete', fn);
}; })(attrs.onComplete);
_super.call(this, attrs);
}
ZoneQueueRunner.prototype.execute = function () {
if (Zone.current !== ambientZone)
throw new Error("Unexpected Zone: " + Zone.current.name);
testProxyZone = ambientZone.fork(new ProxyZoneSpec());
_super.prototype.execute.call(this);
};
return ZoneQueueRunner;
}(QueueRunner));
})();

@@ -78,0 +149,0 @@

@@ -1,1 +0,1 @@

!function(e){function n(t){if(r[t])return r[t].exports;var o=r[t]={exports:{},id:t,loaded:!1};return e[t].call(o.exports,o,o.exports,n),o.loaded=!0,o.exports}var r={};return n.m=e,n.c=r,n.p="",n(0)}([function(e,exports){"use strict";if(!Zone)throw new Error("zone.js does not seem to be installed");jasmine.QueueRunner=function(e){function n(e){var n=Zone.current.getZoneWith("JasmineClearStackZone")||Zone.current.getZoneWith("ProxyZoneSpec")||t;n.scheduleMicroTask("jasmineCleanStack",e)}function r(r){r.clearStack=n,e.call(this,r)}var t=Zone.current;return r.prototype=e.prototype,r}(jasmine.QueueRunner)}]);
!function(n){function e(t){if(r[t])return r[t].exports;var o=r[t]={exports:{},id:t,loaded:!1};return n[t].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var r={};return e.m=n,e.c=r,e.p="",e(0)}([function(n,exports){"use strict";var e=this&&this.__extends||function(n,e){function r(){this.constructor=n}for(var t in e)e.hasOwnProperty(t)&&(n[t]=e[t]);n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)};!function(){function n(n){return function(){return c.run(n,this,arguments)}}function r(n){return 0==n.length?function(){return u.run(n,this)}:function(e){return u.run(n,this,[e])}}if(!Zone)throw new Error("Missing: zone.js");if(!jasmine)throw new Error("Missing: jasmine.js");if(jasmine.__zone_patch__)throw new Error("'jasmine' has already been patched with 'Zone'.");jasmine.__zone_patch__=!0;var t=Zone.SyncTestZoneSpec,o=Zone.ProxyZoneSpec;if(!t)throw new Error("Missing: SyncTestZoneSpec");if(!o)throw new Error("Missing: ProxyZoneSpec");var i=Zone.current,c=i.fork(new t("jasmine.describe")),u=null,s=jasmine.getEnv();["desribe","xdescribe","fdescribe"].forEach(function(e){var r=s[e];s[e]=function(e,t){return r.call(this,e,n(t))}}),["it","xit","fit"].forEach(function(n){var e=s[n];s[n]=function(n,t){return e.call(this,n,r(t))}}),["beforeEach","afterEach"].forEach(function(n){var e=s[n];s[n]=function(n){return e.call(this,r(n))}});var a=jasmine.QueueRunner;jasmine.QueueRunner=function(n){function r(e){e.clearStack=function(n){return n()},e.onComplete=function(n){return function(){u=null,i.scheduleMicroTask("jasmine.onComplete",n)}}(e.onComplete),n.call(this,e)}return e(r,n),r.prototype.execute=function(){if(Zone.current!==i)throw new Error("Unexpected Zone: "+Zone.current.name);u=i.fork(new o),n.prototype.execute.call(this)},r}(a)}()}]);
'use strict';
// Patch jasmine's it and fit functions so that the `done` wrapCallback always resets the zone
// to the jasmine zone, which should be the root zone. (angular/zone.js#91)
if (!Zone) {
throw new Error('zone.js does not seem to be installed');
}
// When you have in async test (test with `done` argument) jasmine will
// execute the next test synchronously in the done handler. This makes sense
// for most tests, but now with zones. With zones running next test
// synchronously means that the current zone does not get cleared. This
// results in a chain of nested zones, which makes it hard to reason about
// it. We override the `clearStack` method which forces jasmine to always
// drain the stack before next test gets executed.
(<any>jasmine).QueueRunner = (function (SuperQueueRunner) {
const originalZone = Zone.current;
// Subclass the `QueueRunner` and override the `clearStack` method.
(() => {
// Patch jasmine's describe/it/beforeEach/afterEach functions so test code always runs
// in a testZone (ProxyZone). (See: angular/zone.js#91 & angular/angular#10503)
if (!Zone) throw new Error("Missing: zone.js");
if (!jasmine) throw new Error("Missing: jasmine.js");
if (jasmine['__zone_patch__']) throw new Error("'jasmine' has already been patched with 'Zone'.");
jasmine['__zone_patch__'] = true;
function alwaysClearStack(fn) {
const zone: Zone = Zone.current.getZoneWith('JasmineClearStackZone')
|| Zone.current.getZoneWith('ProxyZoneSpec')
|| originalZone;
zone.scheduleMicroTask('jasmineCleanStack', fn);
const SyncTestZoneSpec: {new (name: string): ZoneSpec} = Zone['SyncTestZoneSpec'];
const ProxyZoneSpec: {new (): ZoneSpec} = Zone['ProxyZoneSpec'];
if (!SyncTestZoneSpec) throw new Error("Missing: SyncTestZoneSpec");
if (!ProxyZoneSpec) throw new Error("Missing: ProxyZoneSpec");
const ambientZone = Zone.current;
// Create a synchronous-only zone in which to run `describe` blocks in order to raise an
// error if any asynchronous operations are attempted inside of a `describe` but outside of
// a `beforeEach` or `it`.
const syncZone = ambientZone.fork(new SyncTestZoneSpec('jasmine.describe'));
// This is the zone which will be used for running individual tests.
// It will be a proxy zone, so that the tests function can retroactively install
// different zones.
// Example:
// - In beforeEach() do childZone = Zone.current.fork(...);
// - In it() try to do fakeAsync(). The issue is that because the beforeEach forked the
// zone outside of fakeAsync it will be able to escope the fakeAsync rules.
// - Because ProxyZone is parent fo `childZone` fakeAsync can retroactively add
// fakeAsync behavior to the childZone.
let testProxyZone: Zone = null;
// Monkey patch all of the jasmine DSL so that each function runs in appropriate zone.
const jasmineEnv = jasmine.getEnv();
['desribe', 'xdescribe', 'fdescribe'].forEach((methodName) => {
let originalJasmineFn: Function = jasmineEnv[methodName];
jasmineEnv[methodName] = function(description: string, specDefinitions: Function) {
return originalJasmineFn.call(this, description, wrapDescribeInZone(specDefinitions));
}
});
['it', 'xit', 'fit'].forEach((methodName) => {
let originalJasmineFn: Function = jasmineEnv[methodName];
jasmineEnv[methodName] = function(description: string, specDefinitions: Function) {
return originalJasmineFn.call(this, description, wrapTestInZone(specDefinitions));
}
});
['beforeEach', 'afterEach'].forEach((methodName) => {
let originalJasmineFn: Function = jasmineEnv[methodName];
jasmineEnv[methodName] = function(specDefinitions: Function) {
return originalJasmineFn.call(this, wrapTestInZone(specDefinitions));
}
});
/**
* Gets a function wrapping the body of a Jasmine `describe` block to execute in a
* synchronous-only zone.
*/
function wrapDescribeInZone(describeBody: Function): Function {
return function() {
return syncZone.run(describeBody, this, arguments as any as any[]);
}
}
function QueueRunner(options) {
options.clearStack = alwaysClearStack;
SuperQueueRunner.call(this, options);
/**
* Gets a function wrapping the body of a Jasmine `it/beforeEach/afterEach` block to
* execute in a ProxyZone zone.
* This will run in `testProxyZone`. The `testProxyZone` will be reset by the `ZoneQueueRunner`
*/
function wrapTestInZone(testBody: Function): Function {
// The `done` callback is only passed through if the function expects at least one argument.
// Note we have to make a function with correct number of arguments, otherwise jasmine will
// think that all functions are sync or async.
return (testBody.length == 0)
? function() { return testProxyZone.run(testBody, this); }
: function(done) { return testProxyZone.run(testBody, this, [done]); };
}
QueueRunner.prototype = SuperQueueRunner.prototype;
return QueueRunner;
})((<any>jasmine).QueueRunner);
interface QueueRunner {
execute(): void;
}
interface QueueRunnerAttrs {
queueableFns: {fn: Function}[];
onComplete: () => void;
clearStack: (fn) => void;
onException: (error) => void;
catchException: () => boolean;
userContext: any;
timeout: {setTimeout: Function, clearTimeout: Function};
fail: ()=> void;
}
const QueueRunner = (jasmine as any).QueueRunner as { new(attrs: QueueRunnerAttrs): QueueRunner };
(jasmine as any).QueueRunner = class ZoneQueueRunner extends QueueRunner {
constructor(attrs: QueueRunnerAttrs) {
attrs.clearStack = (fn) => fn(); // Don't clear since onComplete will clear.
attrs.onComplete = ((fn) => () => {
// All functions are done, clear the test zone.
testProxyZone = null;
ambientZone.scheduleMicroTask('jasmine.onComplete', fn);
})(attrs.onComplete);
super(attrs);
}
execute() {
if(Zone.current !== ambientZone) throw new Error("Unexpected Zone: " + Zone.current.name);
testProxyZone = ambientZone.fork(new ProxyZoneSpec());
super.execute();
}
};
})();
{
"name": "zone.js",
"version": "0.6.13",
"version": "0.6.14",
"description": "Zones for JavaScript",

@@ -5,0 +5,0 @@ "main": "dist/zone-node.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc