Make sure the queue runner goes async for async specs
- Even if `done` is called synchronously.
See #1327 #1334 jasmine/gulp-jasmine-browser#48
This is a backport of 578f63b9bd
to 2.6.x.
This commit is contained in:
@@ -65,6 +65,10 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
var clearTimeout = function () {
|
||||
Function.prototype.apply.apply(self.timeout.clearTimeout, [j$.getGlobal(), [timeoutId]]);
|
||||
},
|
||||
completedSynchronously = true,
|
||||
setTimeout = function(delayedFn, delay) {
|
||||
return Function.prototype.apply.apply(self.timeout.setTimeout, [j$.getGlobal(), [delayedFn, delay]]);
|
||||
},
|
||||
handleError = function(error) {
|
||||
onException(error);
|
||||
next();
|
||||
@@ -72,7 +76,13 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
next = once(function () {
|
||||
clearTimeout(timeoutId);
|
||||
self.globalErrors.popListener(handleError);
|
||||
self.run(queueableFns, iterativeIndex + 1);
|
||||
if (completedSynchronously) {
|
||||
setTimeout(function() {
|
||||
self.run(queueableFns, iterativeIndex + 1);
|
||||
});
|
||||
} else {
|
||||
self.run(queueableFns, iterativeIndex + 1);
|
||||
}
|
||||
}),
|
||||
timeoutId;
|
||||
|
||||
@@ -84,15 +94,16 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
self.globalErrors.pushListener(handleError);
|
||||
|
||||
if (queueableFn.timeout) {
|
||||
timeoutId = Function.prototype.apply.apply(self.timeout.setTimeout, [j$.getGlobal(), [function() {
|
||||
timeoutId = setTimeout(function() {
|
||||
var error = new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.');
|
||||
onException(error);
|
||||
next();
|
||||
}, queueableFn.timeout()]]);
|
||||
}, queueableFn.timeout());
|
||||
}
|
||||
|
||||
try {
|
||||
queueableFn.fn.call(self.userContext, next);
|
||||
completedSynchronously = false;
|
||||
} catch (e) {
|
||||
handleException(e, queueableFn);
|
||||
next();
|
||||
|
||||
Reference in New Issue
Block a user