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
+1 -84
View File
@@ -222,90 +222,7 @@ describe("Spec", function() {
expect(specNameSpy.calls.mostRecent().args[0].id).toEqual(spec.id);
});
it("sets a timeout for async functions to keep them from running forever", function() {
var queueRunnerSpy = jasmine.createSpy('queue runner'),
setTimeoutSpy = jasmine.createSpy('setTimeout'),
spec = new j$.Spec({
beforeFns: function() { return [function(done) { }]; },
fn: function(done) { },
afterFns: function() { return [function(done) { }]; },
timer: {
setTimeout: setTimeoutSpy,
clearTimeout: function() {}
},
queueRunnerFactory: queueRunnerSpy
});
spec.execute();
var fns = queueRunnerSpy.calls.mostRecent().args[0].fns;
for (var i = 0; i < fns.length; i++) {
fns[i]();
}
expect(setTimeoutSpy.calls.count()).toEqual(3);
expect(setTimeoutSpy).toHaveBeenCalledWith(jasmine.any(Function), j$.DEFAULT_TIMEOUT_INTERVAL);
});
it("resets the timeout timer when an async before throws an exception", function() {
var queueRunnerSpy = jasmine.createSpy('queueRunner'),
clearTimeoutSpy = jasmine.createSpy('clear timeout'),
spec = new j$.Spec({
beforeFns: function() { return [function(done) {}]; },
fn: function() { },
timer: {
setTimeout: function () { return 920; },
clearTimeout: clearTimeoutSpy
},
queueRunnerFactory: queueRunnerSpy
});
spec.execute();
queueRunnerSpy.calls.mostRecent().args[0].fns[0]();
queueRunnerSpy.calls.mostRecent().args[0].onException(new Error());
expect(clearTimeoutSpy).toHaveBeenCalledWith(920);
});
it("resets the timeout timer when an async spec throws an exception", function() {
var queueRunnerSpy = jasmine.createSpy('queueRunner'),
clearTimeoutSpy = jasmine.createSpy('clear timeout'),
spec = new j$.Spec({
fn: function(done) { },
timer: {
setTimeout: function () { return 920; },
clearTimeout: clearTimeoutSpy
},
queueRunnerFactory: queueRunnerSpy
});
spec.execute();
queueRunnerSpy.calls.mostRecent().args[0].fns[0]();
queueRunnerSpy.calls.mostRecent().args[0].onException(new Error());
expect(clearTimeoutSpy).toHaveBeenCalledWith(920);
});
it("resets the timeout timer when an async after spec throws an exception", function() {
var queueRunnerSpy = jasmine.createSpy('queueRunner'),
clearTimeoutSpy = jasmine.createSpy('clear timeout'),
spec = new j$.Spec({
fn: function() { },
afterFns: function() { return [function(done) {}]; },
timer: {
setTimeout: function () { return 920; },
clearTimeout: clearTimeoutSpy
},
queueRunnerFactory: queueRunnerSpy
});
spec.execute();
queueRunnerSpy.calls.mostRecent().args[0].fns[1]();
queueRunnerSpy.calls.mostRecent().args[0].onException(new Error());
expect(clearTimeoutSpy).toHaveBeenCalledWith(920);
});
describe("when a spec is marked pending during execution", function() {
describe("when a spec is marked pending during execution", function() {
it("should mark the spec as pending", function() {
var fakeQueueRunner = function(opts) {
opts.onException(new Error(j$.Spec.pendingSpecExceptionMessage));