test-agent
Advanced tools
Comparing version 0.6.2 to 0.6.3
@@ -0,1 +1,5 @@ | ||
# 0.6.3 | ||
- Fix #22 by implementing require queues. | ||
Now nested requires should work as expected. | ||
# 0.6.2 | ||
@@ -2,0 +6,0 @@ - Fixed issues where errors thrown from setup/beforeEach would |
@@ -13,4 +13,7 @@ (function(window) { | ||
this._cached = {}; | ||
//queue stuff | ||
this._queue = []; | ||
this.doneCallbacks = []; | ||
this.pending = 0; | ||
@@ -31,2 +34,12 @@ if (typeof(options) === 'undefined') { | ||
/** | ||
* Queue for script loads. | ||
*/ | ||
_queue: null, | ||
/** | ||
* Used for queue identification. | ||
*/ | ||
_currentId: null, | ||
/** | ||
* Prefix for all loaded files | ||
@@ -38,3 +51,2 @@ * | ||
/** | ||
@@ -80,15 +92,2 @@ * javascript content type. | ||
/** | ||
* _decrements pending and fires done callbacks | ||
*/ | ||
_decrementPending: function _decrementPending() { | ||
if (this.pending > 0) { | ||
this.pending--; | ||
} | ||
if (this.pending <= 0) { | ||
this._fireCallbacks(); | ||
} | ||
}, | ||
_fireCallbacks: function _fireCallbacks() { | ||
@@ -113,2 +112,23 @@ var callback; | ||
/** | ||
* Begins an item in the queue. | ||
*/ | ||
_begin: function() { | ||
var item = this._queue[0]; | ||
if (item) { | ||
item(); | ||
} else { | ||
this._fireCallbacks(); | ||
} | ||
}, | ||
/** | ||
* Moves to the next item in the queue. | ||
*/ | ||
_next: function() { | ||
this._queue.shift(); | ||
this._begin(); | ||
}, | ||
/** | ||
* Loads given script into current target window. | ||
@@ -121,3 +141,20 @@ * If file has been previously loaded it will not | ||
*/ | ||
require: function require(url, callback) { | ||
require: function(url, callback) { | ||
this._queue.push( | ||
this._require.bind(this, url, callback) | ||
); | ||
if (this._queue.length === 1) { | ||
this._begin(); | ||
} | ||
}, | ||
/** | ||
* Function that does the actual require work work. | ||
* Handles calling ._next on cached file or on onload | ||
* success. | ||
* | ||
* @private | ||
*/ | ||
_require: function require(url, callback) { | ||
var prefix = this.prefix, | ||
@@ -131,9 +168,5 @@ suffix = '', | ||
if (callback) { | ||
if (this.pending) { | ||
this.done(callback); | ||
} else { | ||
callback(); | ||
} | ||
callback(); | ||
} | ||
return; | ||
return this._next(); | ||
} | ||
@@ -154,11 +187,9 @@ | ||
element.type = this.type; | ||
element.onload = function scriptOnLoad() { | ||
element.onload = function onload() { | ||
if (callback) { | ||
callback(); | ||
} | ||
self._decrementPending(); | ||
}; | ||
self._next(); | ||
} | ||
this.pending++; | ||
document.getElementsByTagName('head')[0].appendChild(element); | ||
@@ -165,0 +196,0 @@ } |
{ | ||
"name": "test-agent", | ||
"version": "0.6.2", | ||
"version": "0.6.3", | ||
"author": "James Lal", | ||
@@ -5,0 +5,0 @@ "description": "execute client side tests from browser report back to cli", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
302790
10713