Comparing version 0.3.0 to 0.4.0
@@ -9,3 +9,4 @@ // Karma configuration | ||
'*-zone.js', | ||
'test/lib/brick.js', | ||
//'test/lib/brick.js', | ||
'test/util.js', | ||
'test/**/*.spec.js', | ||
@@ -19,3 +20,3 @@ {pattern: 'test/assets/**/*.html', watched: true, served: true, included: false} | ||
port: 9876, | ||
//port: 9876, | ||
colors: true, | ||
@@ -22,0 +23,0 @@ |
{ | ||
"name": "zone.js", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Zones for JavaScript", | ||
@@ -10,3 +10,3 @@ "main": "zone.js", | ||
"scripts": { | ||
"test": "./node_modules/.bin/karma start --browsers Firefox --single-run", | ||
"test": "karma start karma.conf.js", | ||
"serve": "python -m SimpleHTTPServer 8000" | ||
@@ -16,3 +16,3 @@ }, | ||
"type": "git", | ||
"url": "git://github.com/btford/zone.js.git" | ||
"url": "git://github.com/angular/zone.js.git" | ||
}, | ||
@@ -22,9 +22,14 @@ "author": "Brian Ford", | ||
"bugs": { | ||
"url": "https://github.com/btford/zone.js/issues" | ||
"url": "https://github.com/angular/zone.js/issues" | ||
}, | ||
"devDependencies": { | ||
"karma": "~0.10.2", | ||
"karma-jasmine": "~0.1.3", | ||
"karma-firefox-launcher": "~0.1.0" | ||
"jasmine-core": "^2.2.0", | ||
"karma": "^0.12.31", | ||
"karma-chrome-launcher": "^0.1.7", | ||
"karma-firefox-launcher": "^0.1.4", | ||
"karma-jasmine": "^0.3.5", | ||
"karma-safari-launcher": "^0.1.1", | ||
"karma-sauce-launcher": "^0.2.10", | ||
"nodejs-websocket": "^1.2.0" | ||
} | ||
} |
@@ -261,2 +261,3 @@ # Zone.js | ||
* [Async stack traces in Chrome](http://www.html5rocks.com/en/tutorials/developertools/async-call-stack/) | ||
* [strongloop/zone](https://github.com/strongloop/zone) | ||
@@ -263,0 +264,0 @@ |
@@ -14,9 +14,13 @@ 'use strict'; | ||
log = []; | ||
jasmine.Clock.useMock(); | ||
}); | ||
it('should produce long stack traces', function () { | ||
it('should produce long stack traces', function (done) { | ||
lstz.run(function () { | ||
setTimeout(function () { | ||
setTimeout(function () { | ||
setTimeout(function () { | ||
expect(log[0]).toBe('Error: hello'); | ||
expect(log[1].split('--- ').length).toBe(4); | ||
done(); | ||
}, 0); | ||
throw new Error('hello'); | ||
@@ -26,11 +30,6 @@ }, 0); | ||
}); | ||
jasmine.Clock.tick(0); | ||
expect(log[0]).toBe('Error: hello'); | ||
expect(log[1].split('--- ').length).toBe(4); | ||
}); | ||
it('should filter based on stackFramesFilter', function () { | ||
it('should filter based on stackFramesFilter', function (done) { | ||
lstz.fork({ | ||
@@ -43,2 +42,6 @@ stackFramesFilter: function (line) { | ||
setTimeout(function () { | ||
setTimeout(function () { | ||
expect(log[1]).not.toContain('jasmine.js'); | ||
done(); | ||
}, 0); | ||
throw new Error('hello'); | ||
@@ -48,6 +51,3 @@ }, 0); | ||
}); | ||
jasmine.Clock.tick(0); | ||
expect(log[1]).not.toContain('jasmine.js'); | ||
}); | ||
}); |
'use strict'; | ||
describe('HTML Imports', function () { | ||
if (!supportsImports()) { | ||
console.log('WARNING: HTML Imports test (missing this API)'); | ||
return; | ||
} | ||
describe('HTML Imports', ifEnvSupports(supportsImports, function () { | ||
var flag, hasParent; | ||
beforeEach(function () { | ||
flag = false; | ||
hasParent = false; | ||
}); | ||
it('should work with addEventListener', function () { | ||
var link; | ||
runs(function () { | ||
link = document.createElement('link'); | ||
link.rel = 'import'; | ||
link.href = 'someUrl'; | ||
link.addEventListener('error', setFlag); | ||
document.head.appendChild(link); | ||
}); | ||
waitsFor(flagToBeTrue, 'template to resolve', 100); | ||
runs(function() { | ||
expect(hasParent).toBe(true); | ||
it('should work with addEventListener', function (done) { | ||
var link = document.createElement('link'); | ||
link.rel = 'import'; | ||
link.href = 'someUrl'; | ||
link.addEventListener('error', function () { | ||
expect(window.zone.parent).toBeDefined(); | ||
document.head.removeChild(link); | ||
done(); | ||
}); | ||
document.head.appendChild(link); | ||
}); | ||
it('should work with onerror', function () { | ||
var link; | ||
runs(function () { | ||
link = document.createElement('link'); | ||
link.rel = 'import'; | ||
link.href = 'anotherUrl'; | ||
link.onerror = setFlag; | ||
document.head.appendChild(link); | ||
}); | ||
waitsFor(flagToBeTrue, 'template to resolve', 100); | ||
runs(function() { | ||
expect(hasParent).toBe(true); | ||
it('should work with onerror', function (done) { | ||
var link = document.createElement('link'); | ||
link.rel = 'import'; | ||
link.href = 'anotherUrl'; | ||
link.onerror = function () { | ||
expect(window.zone.parent).toBeDefined(); | ||
document.head.removeChild(link); | ||
}); | ||
done(); | ||
}; | ||
document.head.appendChild(link); | ||
}); | ||
it('should work with onload', function () { | ||
var link; | ||
runs(function () { | ||
link = document.createElement('link'); | ||
link.rel = 'import'; | ||
link.href = '/base/test/assets/import.html'; | ||
link.onload = setFlag; | ||
document.head.appendChild(link); | ||
}); | ||
waitsFor(flagToBeTrue, 'template to resolve', 100); | ||
runs(function() { | ||
expect(hasParent).toBe(true); | ||
it('should work with onload', function (done) { | ||
var link = document.createElement('link'); | ||
link.rel = 'import'; | ||
link.href = '/base/test/assets/import.html'; | ||
link.onload = function () { | ||
expect(window.zone.parent).toBeDefined(); | ||
document.head.removeChild(link); | ||
}); | ||
done(); | ||
}; | ||
document.head.appendChild(link); | ||
}); | ||
})); | ||
function setFlag() { | ||
hasParent = !!window.zone.parent; | ||
flag = true; | ||
} | ||
function flagToBeTrue() { | ||
return flag; | ||
} | ||
}); | ||
function supportsImports() { | ||
return 'import' in document.createElement('link'); | ||
} | ||
supportsImports.message = 'HTML Imports'; |
'use strict'; | ||
describe('MutationObserver', function () { | ||
describe('MutationObserver', ifEnvSupports('MutationObserver', function () { | ||
var elt; | ||
@@ -10,40 +10,16 @@ | ||
it('should work', function () { | ||
if (!window.MutationObserver) { | ||
console.log('WARNING: skipping MutationObserver test (missing this API)'); | ||
return; | ||
} | ||
var flag = false, | ||
hasParent; | ||
runs(function () { | ||
var ob = new MutationObserver(function () { | ||
hasParent = !!window.zone.parent; | ||
flag = true; | ||
}); | ||
ob.observe(elt, { | ||
childList: true | ||
}); | ||
elt.innerHTML = '<p>hey</p>'; | ||
it('should run observers within the zone', function (done) { | ||
var ob = new MutationObserver(function () { | ||
expect(window.zone.parent).toBeDefined(); | ||
done(); | ||
}); | ||
waitsFor(function() { | ||
return flag; | ||
}, 'mutation observer to fire', 100); | ||
runs(function() { | ||
expect(hasParent).toBe(true); | ||
ob.observe(elt, { | ||
childList: true | ||
}); | ||
elt.innerHTML = '<p>hey</p>'; | ||
}); | ||
it('should dequeue upon disconnect', function () { | ||
if (!window.MutationObserver) { | ||
console.log('WARNING: skipping MutationObserver test (missing this API)'); | ||
return; | ||
} | ||
var flag = false, | ||
@@ -67,7 +43,2 @@ childZone = zone.fork({ | ||
it('should enqueue once upon observation', function () { | ||
if (!window.MutationObserver) { | ||
console.log('WARNING: skipping MutationObserver test (missing this API)'); | ||
return; | ||
} | ||
var count = 0, | ||
@@ -93,7 +64,2 @@ childZone = zone.fork({ | ||
it('should only dequeue upon disconnect if something is observed', function () { | ||
if (!window.MutationObserver) { | ||
console.log('WARNING: skipping MutationObserver test (missing this API)'); | ||
return; | ||
} | ||
var flag = false, | ||
@@ -114,37 +80,19 @@ elt = document.createElement('div'), | ||
}); | ||
}); | ||
})); | ||
describe('WebKitMutationObserver', function () { | ||
it('should ensure observers run within the zone', function () { | ||
if (!window.WebKitMutationObserver) { | ||
console.log('WARNING: skipping WebKitMutationObserver test (missing this API)'); | ||
return; | ||
} | ||
describe('WebKitMutationObserver', ifEnvSupports('WebKitMutationObserver', function () { | ||
it('should run observers within the zone', function (done) { | ||
var elt = document.createElement('div'); | ||
var flag = false, | ||
elt = document.createElement('div'), | ||
hasParent; | ||
runs(function () { | ||
var ob = new WebKitMutationObserver(function () { | ||
hasParent = !!window.zone.parent; | ||
flag = true; | ||
}); | ||
ob.observe(elt, { | ||
childList: true | ||
}); | ||
elt.innerHTML = '<p>hey</p>'; | ||
var ob = new WebKitMutationObserver(function () { | ||
expect(window.zone.parent).toBeDefined(); | ||
done(); | ||
}); | ||
waitsFor(function() { | ||
return flag; | ||
}, 'mutation observer to fire', 100); | ||
runs(function() { | ||
expect(hasParent).toBe(true); | ||
ob.observe(elt, { | ||
childList: true | ||
}); | ||
elt.innerHTML = '<p>hey</p>'; | ||
}); | ||
}); | ||
})); |
'use strict'; | ||
describe('Promise', function () { | ||
var flag, hasParent; | ||
beforeEach(function () { | ||
jasmine.Clock.useMock(); | ||
flag = false; | ||
hasParent = false; | ||
}); | ||
it('should work with .then', function () { | ||
it('should work with .then', function (done) { | ||
if (!window.Promise) { | ||
@@ -18,23 +11,11 @@ console.log('WARNING: skipping Promise test (missing this API)'); | ||
runs(function () { | ||
new Promise(function (resolve) { | ||
setTimeout(resolve, 0); | ||
}).then(function () { | ||
hasParent = !!window.zone.parent; | ||
flag = true; | ||
}); | ||
jasmine.Clock.tick(1); | ||
new Promise(function (resolve) { | ||
resolve(); | ||
}).then(function () { | ||
expect(window.zone.parent).toBeDefined(); | ||
done(); | ||
}); | ||
waitsFor(function() { | ||
return flag; | ||
}, 'promise to resolve', 100); | ||
runs(function() { | ||
expect(hasParent).toBe(true); | ||
}); | ||
}); | ||
it('should work with .catch', function () { | ||
it('should work with .catch', function (done) { | ||
if (!window.Promise) { | ||
@@ -44,21 +25,10 @@ return; | ||
runs(function() { | ||
new Promise(function (resolve, reject) { | ||
setTimeout(reject, 0); | ||
}).catch(function () { | ||
hasParent = !!window.zone.parent; | ||
flag = true; | ||
}); | ||
jasmine.Clock.tick(1); | ||
new Promise(function (resolve, reject) { | ||
reject(); | ||
}).catch(function () { | ||
expect(window.zone.parent).toBeDefined(); | ||
done(); | ||
}); | ||
waitsFor(function() { | ||
return flag; | ||
}, 'promise to reject', 100); | ||
runs(function() { | ||
expect(hasParent).toBe(true); | ||
}); | ||
}); | ||
}); |
@@ -8,12 +8,6 @@ /* | ||
describe('document.registerElement', function () { | ||
if (!('registerElement' in document)) { | ||
console.log('WARNING: skipping document.registerElement test (missing this API)'); | ||
return; | ||
} | ||
describe('document.registerElement', ifEnvSupports(registerElement, function () { | ||
var flag, hasParent; | ||
// register a custom element for each callback | ||
var callbacks = [ | ||
var callbackNames = [ | ||
'created', | ||
@@ -25,11 +19,10 @@ 'attached', | ||
function flagAndCheckZone() { | ||
flag = true; | ||
hasParent = !!window.zone.parent; | ||
} | ||
var callbacks = {}; | ||
var customElements = callbacks.map(function (callbackName) { | ||
var customElements = callbackNames.map(function (callbackName) { | ||
var fullCallbackName = callbackName + 'Callback'; | ||
var proto = Object.create(HTMLElement.prototype); | ||
proto[fullCallbackName] = flagAndCheckZone; | ||
proto[fullCallbackName] = function (arg) { | ||
callbacks[callbackName](arg); | ||
}; | ||
return document.registerElement('x-' + callbackName.toLowerCase(), { | ||
@@ -41,122 +34,87 @@ prototype: proto | ||
beforeEach(function () { | ||
flag = false; | ||
hasParent = false; | ||
it('should work with createdCallback', function (done) { | ||
callbacks.created = function () { | ||
expect(window.zone.parent).toBeDefined(); | ||
done(); | ||
}; | ||
var elt = document.createElement('x-created'); | ||
}); | ||
it('should work with createdCallback', function () { | ||
runs(function () { | ||
var elt = document.createElement('x-created'); | ||
}); | ||
it('should work with attachedCallback', function (done) { | ||
callbacks.attached = function () { | ||
expect(window.zone.parent).toBeDefined(); | ||
done(); | ||
}; | ||
var elt = document.createElement('x-attached'); | ||
document.body.appendChild(elt); | ||
document.body.removeChild(elt); | ||
}); | ||
waitsFor(function() { | ||
return flag; | ||
}, 'createdCallback to fire', 100); | ||
runs(function() { | ||
expect(hasParent).toBe(true); | ||
}); | ||
it('should work with detachedCallback', function (done) { | ||
callbacks.detached = function () { | ||
expect(window.zone.parent).toBeDefined(); | ||
done(); | ||
}; | ||
var elt = document.createElement('x-detached'); | ||
document.body.appendChild(elt); | ||
document.body.removeChild(elt); | ||
}); | ||
it('should work with attachedCallback', function () { | ||
runs(function () { | ||
var elt = document.createElement('x-attached'); | ||
document.body.appendChild(elt); | ||
document.body.removeChild(elt); | ||
}); | ||
waitsFor(function() { | ||
return flag; | ||
}, 'attachedCallback to fire', 100); | ||
runs(function() { | ||
expect(hasParent).toBe(true); | ||
}); | ||
it('should work with attributeChanged', function (done) { | ||
callbacks.attributeChanged = function () { | ||
expect(window.zone.parent).toBeDefined(); | ||
done(); | ||
}; | ||
var elt = document.createElement('x-attributechanged'); | ||
elt.id = 'bar'; | ||
}); | ||
it('should work with detachedCallback', function () { | ||
runs(function () { | ||
var elt = document.createElement('x-detached'); | ||
document.body.appendChild(elt); | ||
document.body.removeChild(elt); | ||
it('should work with non-writable, non-configurable prototypes created with defineProperty', function (done) { | ||
var proto = Object.create(HTMLElement.prototype); | ||
Object.defineProperty(proto, 'createdCallback', { | ||
writeable: false, | ||
configurable: false, | ||
value: checkZone | ||
}); | ||
waitsFor(function() { | ||
return flag; | ||
}, 'detachedCallback to fire', 100); | ||
runs(function() { | ||
expect(hasParent).toBe(true); | ||
document.registerElement('x-prop-desc', { | ||
prototype: proto | ||
}); | ||
}); | ||
var elt = document.createElement('x-prop-desc'); | ||
it('should work with attributeChanged', function () { | ||
runs(function () { | ||
var elt = document.createElement('x-attributechanged'); | ||
elt.id = 'bar'; | ||
}); | ||
waitsFor(function() { | ||
return flag; | ||
}, 'attributeChanged to fire', 100); | ||
runs(function() { | ||
expect(hasParent).toBe(true); | ||
}); | ||
function checkZone() { | ||
expect(window.zone.parent).toBeDefined(); | ||
done(); | ||
} | ||
}); | ||
it('should work with prototypes that have non-writable, non-configurable descriptors', function () { | ||
runs(function () { | ||
var proto = Object.create(HTMLElement.prototype); | ||
Object.defineProperty(proto, 'createdCallback', { | ||
it('should work with non-writable, non-configurable prototypes created with defineProperties', function (done) { | ||
var proto = Object.create(HTMLElement.prototype); | ||
Object.defineProperties(proto, { | ||
createdCallback: { | ||
writeable: false, | ||
configurable: false, | ||
value: flagAndCheckZone | ||
}); | ||
document.registerElement('x-prop-desc', { | ||
prototype: proto | ||
}); | ||
var elt = document.createElement('x-prop-desc'); | ||
value: checkZone | ||
} | ||
}); | ||
document.registerElement('x-props-desc', { | ||
prototype: proto | ||
}); | ||
var elt = document.createElement('x-props-desc'); | ||
waitsFor(function() { | ||
return flag; | ||
}, 'createdCallback to fire', 100); | ||
runs(function() { | ||
expect(hasParent).toBe(true); | ||
}); | ||
function checkZone() { | ||
expect(window.zone.parent).toBeDefined(); | ||
done(); | ||
} | ||
}); | ||
})); | ||
it('should work with prototypes that have non-writable, non-configurable descriptors', function () { | ||
runs(function () { | ||
var proto = Object.create(HTMLElement.prototype); | ||
Object.defineProperties(proto, { | ||
createdCallback: { | ||
writeable: false, | ||
configurable: false, | ||
value: flagAndCheckZone | ||
} | ||
}); | ||
document.registerElement('x-props-desc', { | ||
prototype: proto | ||
}); | ||
var elt = document.createElement('x-props-desc'); | ||
}); | ||
waitsFor(function() { | ||
return flag; | ||
}, 'createdCallback to fire', 100); | ||
runs(function() { | ||
expect(hasParent).toBe(true); | ||
}); | ||
}); | ||
}); | ||
function registerElement() { | ||
return ('registerElement' in document); | ||
} | ||
registerElement.message = 'document.registerElement'; |
'use strict'; | ||
describe('requestAnimationFrame', function () { | ||
var flag, hasParent, skip = false; | ||
it('should work', function (done) { | ||
it('should run the passed callback in a zone', function (done) { | ||
if (!window.requestAnimationFrame) { | ||
console.log('WARNING: skipping requestAnimationFrame test (missing this API)'); | ||
return; | ||
return done(); | ||
} | ||
@@ -17,36 +14,6 @@ | ||
// the same | ||
runs(function() { | ||
flag = false; | ||
window.requestAnimationFrame(function () { | ||
flag = true; | ||
}); | ||
setTimeout(function () { | ||
skip = true; | ||
flag = true; | ||
console.log('WARNING: skipping requestAnimationFrame test (not firing rAF)'); | ||
}, 50); | ||
window.requestAnimationFrame(function () { | ||
expect(window.zone.parent).toBeDefined(); | ||
done(); | ||
}); | ||
waitsFor(function() { | ||
return flag; | ||
}, "requestAnimationFrame to run", 100); | ||
runs(function() { | ||
flag = false; | ||
hasParent = false; | ||
window.requestAnimationFrame(function () { | ||
hasParent = !!window.zone.parent; | ||
flag = true; | ||
}); | ||
}); | ||
waitsFor(function() { | ||
return flag || skip; | ||
}, "requestAnimationFrame to run", 100); | ||
runs(function() { | ||
expect(hasParent || skip).toBe(true); | ||
}); | ||
}); | ||
@@ -56,9 +23,6 @@ }); | ||
describe('mozRequestAnimationFrame', function () { | ||
var flag, hasParent, skip = false; | ||
it('should work', function (done) { | ||
it('should run the passed callback in a zone', function (done) { | ||
if (!window.mozRequestAnimationFrame) { | ||
console.log('WARNING: skipping mozRequestAnimationFrame test (missing this API)'); | ||
return; | ||
return done(); | ||
} | ||
@@ -70,36 +34,6 @@ | ||
// the same | ||
runs(function() { | ||
flag = false; | ||
window.mozRequestAnimationFrame(function () { | ||
flag = true; | ||
}); | ||
setTimeout(function () { | ||
skip = true; | ||
flag = true; | ||
console.log('WARNING: skipping mozRequestAnimationFrame test (not firing rAF)'); | ||
}, 50); | ||
window.mozRequestAnimationFrame(function () { | ||
expect(window.zone.parent).toBeDefined(); | ||
done(); | ||
}); | ||
waitsFor(function() { | ||
return flag; | ||
}, 'mozRequestAnimationFrame to run', 100); | ||
runs(function() { | ||
flag = false; | ||
hasParent = false; | ||
window.mozRequestAnimationFrame(function () { | ||
hasParent = !!window.zone.parent; | ||
flag = true; | ||
}); | ||
}); | ||
waitsFor(function() { | ||
return flag || skip; | ||
}, 'mozRequestAnimationFrame to run', 100); | ||
runs(function() { | ||
expect(hasParent || skip).toBe(true); | ||
}); | ||
}); | ||
@@ -109,9 +43,6 @@ }); | ||
describe('webkitRequestAnimationFrame', function () { | ||
var flag, hasParent, skip = false; | ||
it('should work', function (done) { | ||
it('should run the passed callback in a zone', function (done) { | ||
if (!window.webkitRequestAnimationFrame) { | ||
console.log('WARNING: skipping webkitRequestAnimationFrame test (missing this API)'); | ||
return; | ||
return done(); | ||
} | ||
@@ -123,37 +54,7 @@ | ||
// the same | ||
runs(function() { | ||
flag = false; | ||
window.webkitRequestAnimationFrame(function () { | ||
flag = true; | ||
}); | ||
setTimeout(function () { | ||
skip = true; | ||
flag = true; | ||
console.log('WARNING: skipping webkitRequestAnimationFrame test (not firing rAF)'); | ||
}, 50); | ||
window.webkitRequestAnimationFrame(function () { | ||
expect(window.zone.parent).toBeDefined(); | ||
done(); | ||
}); | ||
waitsFor(function() { | ||
return flag; | ||
}, 'webkitRequestAnimationFrame to run', 100); | ||
runs(function() { | ||
flag = false; | ||
hasParent = false; | ||
window.webkitRequestAnimationFrame(function () { | ||
hasParent = !!window.zone.parent; | ||
flag = true; | ||
}); | ||
}); | ||
waitsFor(function() { | ||
return flag || skip; | ||
}, 'webkitRequestAnimationFrame to run', 100); | ||
runs(function() { | ||
expect(hasParent || skip).toBe(true); | ||
}); | ||
}); | ||
}); |
@@ -7,6 +7,5 @@ 'use strict'; | ||
zone.mark = 'root'; | ||
jasmine.Clock.useMock(); | ||
}); | ||
it('should work with setInterval', function () { | ||
it('should work with setInterval', function (done) { | ||
var childZone = window.zone.fork({ | ||
@@ -24,12 +23,11 @@ mark: 'child' | ||
// creates implied zone in all callbacks. | ||
expect(zone).not.toEqual(childZone); | ||
expect(zone.parent).toEqual(childZone); | ||
expect(zone.mark).toEqual('child'); // proto inherited | ||
expect(zone).not.toBe(childZone); | ||
expect(zone.parent).toBe(childZone); | ||
expect(zone.mark).toBe('child'); // proto inherited | ||
clearInterval(cancelId); | ||
done(); | ||
}, 10); | ||
jasmine.Clock.tick(11); | ||
expect(zone.mark).toEqual('child'); | ||
clearInterval(cancelId); | ||
}); | ||
@@ -36,0 +34,0 @@ |
@@ -7,6 +7,5 @@ 'use strict'; | ||
zone.mark = 'root'; | ||
jasmine.Clock.useMock(); | ||
}); | ||
it('should work with setTimeout', function () { | ||
it('should work with setTimeout', function (done) { | ||
@@ -28,2 +27,3 @@ var childZone = window.zone.fork({ | ||
expect(zone.mark).toEqual('child'); // proto inherited | ||
done(); | ||
}, 0); | ||
@@ -37,12 +37,12 @@ | ||
it('should allow canceling of fns registered with setTimeout', function () { | ||
it('should allow canceling of fns registered with setTimeout', function (done) { | ||
var spy = jasmine.createSpy(); | ||
var cancelId = window.setTimeout(spy, 0); | ||
window.clearTimeout(cancelId); | ||
jasmine.Clock.tick(1); | ||
expect(spy).not.toHaveBeenCalled(); | ||
setTimeout(function () { | ||
expect(spy).not.toHaveBeenCalled(); | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -5,46 +5,20 @@ 'use strict'; | ||
it('should work with onreadystatechange', function () { | ||
var flag = false, | ||
hasParent; | ||
runs(function () { | ||
var req = new XMLHttpRequest(); | ||
req.onreadystatechange = function () { | ||
hasParent = !!window.zone.parent; | ||
flag = true; | ||
}; | ||
req.open('get', '/', true); | ||
req.send(); | ||
}); | ||
waitsFor(function() { | ||
return flag; | ||
}, 'HTTP request to resolve', 100); | ||
runs(function() { | ||
expect(hasParent).toBe(true); | ||
}); | ||
it('should work with onreadystatechange', function (done) { | ||
var req = new XMLHttpRequest(); | ||
req.onreadystatechange = function () { | ||
expect(window.zone.parent).toBeDefined(); | ||
done(); | ||
}; | ||
req.open('get', '/', true); | ||
req.send(); | ||
}); | ||
it('should work with onprogress', function () { | ||
var flag = false, | ||
hasParent; | ||
runs(function () { | ||
var req = new XMLHttpRequest(); | ||
req.onprogress = function () { | ||
hasParent = !!window.zone.parent; | ||
flag = true; | ||
}; | ||
req.open('get', '/', true); | ||
req.send(); | ||
}); | ||
waitsFor(function() { | ||
return flag; | ||
}, 'HTTP request to resolve', 100); | ||
runs(function() { | ||
expect(hasParent).toBe(true); | ||
}); | ||
it('should work with onprogress', function (done) { | ||
var req = new XMLHttpRequest(); | ||
req.onprogress = function () { | ||
expect(window.zone.parent).toBeDefined(); | ||
done(); | ||
}; | ||
req.open('get', '/', true); | ||
req.send(); | ||
}); | ||
@@ -51,0 +25,0 @@ |
@@ -11,6 +11,2 @@ 'use strict'; | ||
beforeEach(function () { | ||
jasmine.Clock.useMock(); | ||
}); | ||
it('should fire beforeTask before a zone runs a function', function () { | ||
@@ -29,2 +25,3 @@ var enterSpy = jasmine.createSpy(); | ||
it('should fire afterTask after a zone runs a function', function () { | ||
@@ -43,3 +40,4 @@ var leaveSpy = jasmine.createSpy(); | ||
it('should fire onZoneCreated when a zone is forked', function () { | ||
it('should fire onZoneCreated when a zone is forked', function (done) { | ||
var createdSpy = jasmine.createSpy(); | ||
@@ -60,17 +58,11 @@ var counter = 0; | ||
setTimeout(function () { | ||
expect(counter).toBe(2); | ||
}, 0); | ||
setTimeout(function () {}, 0); | ||
expect(counter).toBe(1); | ||
setTimeout(function () { | ||
expect(counter).toBe(0); | ||
setTimeout(done, 5); | ||
expect(counter).toBe(1); | ||
setTimeout(function () {}, 0); | ||
expect(counter).toBe(2); | ||
}, 0); | ||
expect(counter).toBe(2); | ||
jasmine.Clock.tick(1); | ||
expect(counter).toBe(0); | ||
}); | ||
@@ -86,2 +78,3 @@ }); | ||
it('should fire onError if a function run by a zone throws', function () { | ||
@@ -102,2 +95,3 @@ var errorSpy = jasmine.createSpy(); | ||
it('should allow you to override alert', function () { | ||
@@ -109,5 +103,2 @@ var spy = jasmine.createSpy(); | ||
//alert('foo'); | ||
//expect(spy).not.toHaveBeenCalled(); | ||
myZone.run(function () { | ||
@@ -121,2 +112,3 @@ alert('foo'); | ||
it('should allow zones to be run from within another zone', function () { | ||
@@ -139,2 +131,3 @@ var a = zone.fork({ | ||
describe('fork', function () { | ||
@@ -141,0 +134,0 @@ it('should fork deep copy', function () { |
15
zone.js
@@ -360,2 +360,3 @@ 'use strict'; | ||
Zone.patchClass('XMLHttpRequest'); | ||
Zone.patchWebSocket(); | ||
} | ||
@@ -417,2 +418,13 @@ | ||
// we have to patch the instance since the proto is non-configurable | ||
Zone.patchWebSocket = function() { | ||
var WS = window.WebSocket; | ||
window.WebSocket = function(a, b) { | ||
var socket = arguments.length > 1 ? new WS(a, b) : new WS(a); | ||
Zone.patchProperties(socket, ['onclose', 'onerror', 'onmessage', 'onopen']); | ||
return socket; | ||
}; | ||
} | ||
// wrap some native API on `window` | ||
@@ -463,2 +475,3 @@ Zone.patchClass = function (className) { | ||
// wrap some native API on `window` | ||
@@ -606,3 +619,3 @@ Zone.patchMutationObserverClass = function (className) { | ||
Zone.eventNames = 'copy cut paste abort blur focus canplay canplaythrough change click contextmenu dblclick drag dragend dragenter dragleave dragover dragstart drop durationchange emptied ended input invalid keydown keypress keyup load loadeddata loadedmetadata loadstart mousedown mouseenter mouseleave mousemove mouseout mouseover mouseup pause play playing progress ratechange reset scroll seeked seeking select show stalled submit suspend timeupdate volumechange waiting mozfullscreenchange mozfullscreenerror mozpointerlockchange mozpointerlockerror error webglcontextrestored webglcontextlost webglcontextcreationerror'.split(' '); | ||
Zone.eventNames = 'copy cut paste abort blur focus canplay canplaythrough change click contextmenu dblclick drag dragend dragenter dragleave dragover dragstart drop durationchange emptied ended input invalid keydown keypress keyup load loadeddata loadedmetadata loadstart message mousedown mouseenter mouseleave mousemove mouseout mouseover mouseup pause play playing progress ratechange reset scroll seeked seeking select show stalled submit suspend timeupdate volumechange waiting mozfullscreenchange mozfullscreenerror mozpointerlockchange mozpointerlockerror error webglcontextrestored webglcontextlost webglcontextcreationerror'.split(' '); | ||
Zone.onEventNames = Zone.eventNames.map(function (property) { | ||
@@ -609,0 +622,0 @@ return 'on' + property; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 5 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
42
266
0
348248
8
5749
10