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:
Steve Gravrock
2017-06-06 15:38:36 -07:00
parent 5d1d19f494
commit a3bc74776a
4 changed files with 106 additions and 60 deletions

View File

@@ -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();