Refactor Spec and QueueRunner [#62585700]

- QueueRunner now responsible for timing out async specs instead of
   Spec
 - Make sure only spec functions are timeoutable and not suites (due to
   the refactor)
This commit is contained in:
Greg Cobb and Sheel Choksi
2014-02-25 12:15:12 -08:00
parent 84160ff51d
commit 5aac3e3292
8 changed files with 143 additions and 174 deletions

View File

@@ -14,8 +14,6 @@ getJasmineRequireObj().Spec = function(j$) {
this.queueRunnerFactory = attrs.queueRunnerFactory || function() {};
this.catchingExceptions = attrs.catchingExceptions || function() { return true; };
this.timer = attrs.timer || {setTimeout: setTimeout, clearTimeout: clearTimeout};
if (!this.fn) {
this.pend();
}
@@ -40,8 +38,7 @@ getJasmineRequireObj().Spec = function(j$) {
};
Spec.prototype.execute = function(onComplete) {
var self = this,
timeout;
var self = this;
this.onStart(this);
@@ -50,42 +47,16 @@ getJasmineRequireObj().Spec = function(j$) {
return;
}
function timeoutable(fn) {
return function(done) {
timeout = Function.prototype.apply.apply(self.timer.setTimeout, [j$.getGlobal(), [function() {
onException(new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.'));
done();
}, j$.DEFAULT_TIMEOUT_INTERVAL]]);
var callDone = function() {
clearTimeoutable();
done();
};
fn.call(this, callDone); //TODO: do we care about more than 1 arg?
};
}
function clearTimeoutable() {
Function.prototype.apply.apply(self.timer.clearTimeout, [j$.getGlobal(), [timeout]]);
timeout = void 0;
}
var allFns = this.beforeFns().concat(this.fn).concat(this.afterFns()),
allTimeoutableFns = [];
for (var i = 0; i < allFns.length; i++) {
var fn = allFns[i];
allTimeoutableFns.push(fn.length > 0 ? timeoutable(fn) : fn);
}
var allFns = this.beforeFns().concat(this.fn).concat(this.afterFns());
this.queueRunnerFactory({
fns: allTimeoutableFns,
fns: allFns,
onException: onException,
onComplete: complete
onComplete: complete,
enforceTimeout: function() { return true; }
});
function onException(e) {
clearTimeoutable();
if (Spec.isPendingSpecException(e)) {
self.pend();
return;