beforeAll/afterAll can be timed out and errors are applied to all children specs

This commit is contained in:
Gregg Van Hove and Sheel Choksi
2014-03-03 16:13:59 -08:00
parent e17a2cb1e0
commit 52026fb0f7
8 changed files with 183 additions and 148 deletions

View File

@@ -11,31 +11,30 @@ getJasmineRequireObj().QueueRunner = function(j$) {
}
function QueueRunner(attrs) {
this.fns = attrs.fns || [];
this.queueableFns = attrs.queueableFns || [];
this.onComplete = attrs.onComplete || function() {};
this.clearStack = attrs.clearStack || function(fn) {fn();};
this.onException = attrs.onException || function() {};
this.catchException = attrs.catchException || function() { return true; };
this.enforceTimeout = attrs.enforceTimeout || function() { return false; };
this.userContext = attrs.userContext || {};
this.timer = attrs.timeout || {setTimeout: setTimeout, clearTimeout: clearTimeout};
}
QueueRunner.prototype.execute = function() {
this.run(this.fns, 0);
this.run(this.queueableFns, 0);
};
QueueRunner.prototype.run = function(fns, recursiveIndex) {
var length = fns.length,
QueueRunner.prototype.run = function(queueableFns, recursiveIndex) {
var length = queueableFns.length,
self = this,
iterativeIndex;
for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) {
var fn = fns[iterativeIndex];
if (fn.length > 0) {
return attemptAsync(fn);
var queueableFn = queueableFns[iterativeIndex];
if (queueableFn.fn.length > 0) {
return attemptAsync(queueableFn);
} else {
attemptSync(fn);
attemptSync(queueableFn);
}
}
@@ -45,33 +44,33 @@ getJasmineRequireObj().QueueRunner = function(j$) {
this.clearStack(this.onComplete);
}
function attemptSync(fn) {
function attemptSync(queueableFn) {
try {
fn.call(self.userContext);
queueableFn.fn.call(self.userContext);
} catch (e) {
handleException(e);
}
}
function attemptAsync(fn) {
function attemptAsync(queueableFn) {
var clearTimeout = function () {
Function.prototype.apply.apply(self.timer.clearTimeout, [j$.getGlobal(), [timeoutId]]);
},
next = once(function () {
clearTimeout(timeoutId);
self.run(fns, iterativeIndex + 1);
self.run(queueableFns, iterativeIndex + 1);
}),
timeoutId;
if (self.enforceTimeout()) {
if (queueableFn.timeout) {
timeoutId = Function.prototype.apply.apply(self.timer.setTimeout, [j$.getGlobal(), [function() {
self.onException(new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.'));
next();
}, j$.DEFAULT_TIMEOUT_INTERVAL]]);
}, queueableFn.timeout()]]);
}
try {
fn.call(self.userContext, next);
queueableFn.fn.call(self.userContext, next);
} catch (e) {
handleException(e);
next();