Fixes issue where mock clock was being used by QueueRunner
- If the mock clock was installed in a beforeAll, the QueueRunner would use the mock clock for its own clock. If the mock clock was ticked more than the default timeout, async specs would timeout. [fixes #783 #792]
This commit is contained in:
@@ -602,7 +602,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
var queueRunnerFactory = function(options) {
|
var queueRunnerFactory = function(options) {
|
||||||
options.catchException = catchException;
|
options.catchException = catchException;
|
||||||
options.clearStack = options.clearStack || clearStack;
|
options.clearStack = options.clearStack || clearStack;
|
||||||
options.timer = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout};
|
options.timeout = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout};
|
||||||
options.fail = self.fail;
|
options.fail = self.fail;
|
||||||
|
|
||||||
new j$.QueueRunner(options).execute();
|
new j$.QueueRunner(options).execute();
|
||||||
@@ -1727,7 +1727,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
this.onException = attrs.onException || function() {};
|
this.onException = attrs.onException || function() {};
|
||||||
this.catchException = attrs.catchException || function() { return true; };
|
this.catchException = attrs.catchException || function() { return true; };
|
||||||
this.userContext = attrs.userContext || {};
|
this.userContext = attrs.userContext || {};
|
||||||
this.timer = attrs.timeout || {setTimeout: setTimeout, clearTimeout: clearTimeout};
|
this.timeout = attrs.timeout || {setTimeout: setTimeout, clearTimeout: clearTimeout};
|
||||||
this.fail = attrs.fail || function() {};
|
this.fail = attrs.fail || function() {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1767,7 +1767,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
|
|
||||||
function attemptAsync(queueableFn) {
|
function attemptAsync(queueableFn) {
|
||||||
var clearTimeout = function () {
|
var clearTimeout = function () {
|
||||||
Function.prototype.apply.apply(self.timer.clearTimeout, [j$.getGlobal(), [timeoutId]]);
|
Function.prototype.apply.apply(self.timeout.clearTimeout, [j$.getGlobal(), [timeoutId]]);
|
||||||
},
|
},
|
||||||
next = once(function () {
|
next = once(function () {
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
@@ -1781,7 +1781,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (queueableFn.timeout) {
|
if (queueableFn.timeout) {
|
||||||
timeoutId = Function.prototype.apply.apply(self.timer.setTimeout, [j$.getGlobal(), [function() {
|
timeoutId = Function.prototype.apply.apply(self.timeout.setTimeout, [j$.getGlobal(), [function() {
|
||||||
var error = new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.');
|
var error = new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.');
|
||||||
onException(error, queueableFn);
|
onException(error, queueableFn);
|
||||||
next();
|
next();
|
||||||
|
|||||||
@@ -861,6 +861,36 @@ describe("Env integration", function() {
|
|||||||
env.execute();
|
env.execute();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should not use the mock clock for asynchronous timeouts", function(){
|
||||||
|
var env = new j$.Env(),
|
||||||
|
reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]),
|
||||||
|
clock = env.clock;
|
||||||
|
|
||||||
|
reporter.jasmineDone.and.callFake(function() {
|
||||||
|
expect(reporter.specDone.calls.count()).toEqual(1);
|
||||||
|
expect(reporter.specDone.calls.argsFor(0)[0]).toEqual(jasmine.objectContaining({status: 'passed'}));
|
||||||
|
});
|
||||||
|
|
||||||
|
env.addReporter(reporter);
|
||||||
|
j$.DEFAULT_TIMEOUT_INTERVAL = 5;
|
||||||
|
|
||||||
|
env.beforeAll(function() {
|
||||||
|
clock.install();
|
||||||
|
});
|
||||||
|
|
||||||
|
env.afterAll(function() {
|
||||||
|
clock.uninstall();
|
||||||
|
});
|
||||||
|
|
||||||
|
env.it("spec that should not time out", function(done) {
|
||||||
|
clock.tick(6);
|
||||||
|
expect(true).toEqual(true);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
env.execute();
|
||||||
|
});
|
||||||
|
|
||||||
it("should wait the specified interval before reporting an afterAll that fails to call done", function(done) {
|
it("should wait the specified interval before reporting an afterAll that fails to call done", function(done) {
|
||||||
var env = new j$.Env(),
|
var env = new j$.Env(),
|
||||||
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
|
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
var queueRunnerFactory = function(options) {
|
var queueRunnerFactory = function(options) {
|
||||||
options.catchException = catchException;
|
options.catchException = catchException;
|
||||||
options.clearStack = options.clearStack || clearStack;
|
options.clearStack = options.clearStack || clearStack;
|
||||||
options.timer = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout};
|
options.timeout = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout};
|
||||||
options.fail = self.fail;
|
options.fail = self.fail;
|
||||||
|
|
||||||
new j$.QueueRunner(options).execute();
|
new j$.QueueRunner(options).execute();
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
this.onException = attrs.onException || function() {};
|
this.onException = attrs.onException || function() {};
|
||||||
this.catchException = attrs.catchException || function() { return true; };
|
this.catchException = attrs.catchException || function() { return true; };
|
||||||
this.userContext = attrs.userContext || {};
|
this.userContext = attrs.userContext || {};
|
||||||
this.timer = attrs.timeout || {setTimeout: setTimeout, clearTimeout: clearTimeout};
|
this.timeout = attrs.timeout || {setTimeout: setTimeout, clearTimeout: clearTimeout};
|
||||||
this.fail = attrs.fail || function() {};
|
this.fail = attrs.fail || function() {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
|
|
||||||
function attemptAsync(queueableFn) {
|
function attemptAsync(queueableFn) {
|
||||||
var clearTimeout = function () {
|
var clearTimeout = function () {
|
||||||
Function.prototype.apply.apply(self.timer.clearTimeout, [j$.getGlobal(), [timeoutId]]);
|
Function.prototype.apply.apply(self.timeout.clearTimeout, [j$.getGlobal(), [timeoutId]]);
|
||||||
},
|
},
|
||||||
next = once(function () {
|
next = once(function () {
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
@@ -71,7 +71,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (queueableFn.timeout) {
|
if (queueableFn.timeout) {
|
||||||
timeoutId = Function.prototype.apply.apply(self.timer.setTimeout, [j$.getGlobal(), [function() {
|
timeoutId = Function.prototype.apply.apply(self.timeout.setTimeout, [j$.getGlobal(), [function() {
|
||||||
var error = new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.');
|
var error = new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.');
|
||||||
onException(error, queueableFn);
|
onException(error, queueableFn);
|
||||||
next();
|
next();
|
||||||
|
|||||||
Reference in New Issue
Block a user