Merge pull request #401 from sheelc/async_queue_runner
Async queue runner fixes
This commit is contained in:
@@ -1311,27 +1311,28 @@ getJasmineRequireObj().QueueRunner = function() {
|
|||||||
for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) {
|
for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) {
|
||||||
var fn = fns[iterativeIndex];
|
var fn = fns[iterativeIndex];
|
||||||
if (fn.length > 0) {
|
if (fn.length > 0) {
|
||||||
attempt(function() {
|
var attemptSuccessful = attempt(function() {
|
||||||
fn.call(self, function() { self.run(fns, iterativeIndex + 1); });
|
fn.call(self, function() { self.run(fns, iterativeIndex + 1); });
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
|
if(attemptSuccessful) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
attempt(function() { fn.call(self); });
|
attempt(function() { fn.call(self); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var runnerDone = iterativeIndex >= length,
|
var runnerDone = iterativeIndex >= length;
|
||||||
hasBeenAsyncSpec = recursiveIndex > 0;
|
|
||||||
|
|
||||||
if (runnerDone && hasBeenAsyncSpec) {
|
if (runnerDone) {
|
||||||
this.clearStack(this.onComplete);
|
this.clearStack(this.onComplete);
|
||||||
} else if(runnerDone) {
|
|
||||||
this.onComplete();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function attempt(fn) {
|
function attempt(fn) {
|
||||||
try {
|
try {
|
||||||
fn();
|
fn();
|
||||||
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
self.onException(e);
|
self.onException(e);
|
||||||
if (!self.catchException(e)) {
|
if (!self.catchException(e)) {
|
||||||
@@ -1339,6 +1340,7 @@ getJasmineRequireObj().QueueRunner = function() {
|
|||||||
//use a finally block to close the loop in a nice way..
|
//use a finally block to close the loop in a nice way..
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1545,7 +1547,7 @@ getJasmineRequireObj().Suite = function() {
|
|||||||
children = this.children_;
|
children = this.children_;
|
||||||
|
|
||||||
for (var i = 0; i < children.length; i++) {
|
for (var i = 0; i < children.length; i++) {
|
||||||
allFns.push(wrapChild(children[i]));
|
allFns.push(wrapChildAsAsync(children[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.onStart(this);
|
this.onStart(this);
|
||||||
@@ -1563,8 +1565,8 @@ getJasmineRequireObj().Suite = function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function wrapChild(child) {
|
function wrapChildAsAsync(child) {
|
||||||
return function() { child.execute(); };
|
return function(done) { child.execute(done); };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -189,9 +189,34 @@ describe("Env integration", function() {
|
|||||||
env.execute();
|
env.execute();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should run async specs in order, waiting for them to complete", function(done) {
|
||||||
|
var env = new j$.Env(), mutatedVar;
|
||||||
|
|
||||||
|
env.describe("tests", function() {
|
||||||
|
env.beforeEach(function() {
|
||||||
|
mutatedVar = 2;
|
||||||
|
});
|
||||||
|
|
||||||
|
env.it("async spec", function(underTestCallback) {
|
||||||
|
setTimeout(function() {
|
||||||
|
expect(mutatedVar).toEqual(2);
|
||||||
|
underTestCallback();
|
||||||
|
done();
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
env.it("after async spec", function() {
|
||||||
|
mutatedVar = 3;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
env.execute();
|
||||||
|
});
|
||||||
|
|
||||||
// TODO: something is wrong with this spec
|
// TODO: something is wrong with this spec
|
||||||
it("should report as expected", function(done) {
|
it("should report as expected", function(done) {
|
||||||
var reporter = jasmine.createSpyObj('fakeReporter', [
|
var env = new j$.Env(),
|
||||||
|
reporter = jasmine.createSpyObj('fakeReporter', [
|
||||||
"jasmineStarted",
|
"jasmineStarted",
|
||||||
"jasmineDone",
|
"jasmineDone",
|
||||||
"suiteStarted",
|
"suiteStarted",
|
||||||
|
|||||||
@@ -102,6 +102,18 @@ describe("QueueRunner", function() {
|
|||||||
expect(function() { queueRunner.execute(); }).toThrow();
|
expect(function() { queueRunner.execute(); }).toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("continues running the functions even after an exception is thrown in an async spec", function() {
|
||||||
|
var fn = function(done) { throw new Error("error"); },
|
||||||
|
nextFn = jasmine.createSpy("nextFunction");
|
||||||
|
|
||||||
|
queueRunner = new j$.QueueRunner({
|
||||||
|
fns: [fn, nextFn]
|
||||||
|
});
|
||||||
|
|
||||||
|
queueRunner.execute();
|
||||||
|
expect(nextFn).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it("calls a provided complete callback when done", function() {
|
it("calls a provided complete callback when done", function() {
|
||||||
var fn = jasmine.createSpy('fn'),
|
var fn = jasmine.createSpy('fn'),
|
||||||
completeCallback = jasmine.createSpy('completeCallback'),
|
completeCallback = jasmine.createSpy('completeCallback'),
|
||||||
@@ -115,7 +127,7 @@ describe("QueueRunner", function() {
|
|||||||
expect(completeCallback).toHaveBeenCalled();
|
expect(completeCallback).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("with an async spec, calls a provided stack clearing function when done", function() {
|
it("calls a provided stack clearing function when done", function() {
|
||||||
var asyncFn = function(done) { done() },
|
var asyncFn = function(done) { done() },
|
||||||
afterFn = jasmine.createSpy('afterFn'),
|
afterFn = jasmine.createSpy('afterFn'),
|
||||||
completeCallback = jasmine.createSpy('completeCallback'),
|
completeCallback = jasmine.createSpy('completeCallback'),
|
||||||
|
|||||||
@@ -20,27 +20,28 @@ getJasmineRequireObj().QueueRunner = function() {
|
|||||||
for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) {
|
for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) {
|
||||||
var fn = fns[iterativeIndex];
|
var fn = fns[iterativeIndex];
|
||||||
if (fn.length > 0) {
|
if (fn.length > 0) {
|
||||||
attempt(function() {
|
var attemptSuccessful = attempt(function() {
|
||||||
fn.call(self, function() { self.run(fns, iterativeIndex + 1); });
|
fn.call(self, function() { self.run(fns, iterativeIndex + 1); });
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
|
if(attemptSuccessful) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
attempt(function() { fn.call(self); });
|
attempt(function() { fn.call(self); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var runnerDone = iterativeIndex >= length,
|
var runnerDone = iterativeIndex >= length;
|
||||||
hasBeenAsyncSpec = recursiveIndex > 0;
|
|
||||||
|
|
||||||
if (runnerDone && hasBeenAsyncSpec) {
|
if (runnerDone) {
|
||||||
this.clearStack(this.onComplete);
|
this.clearStack(this.onComplete);
|
||||||
} else if(runnerDone) {
|
|
||||||
this.onComplete();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function attempt(fn) {
|
function attempt(fn) {
|
||||||
try {
|
try {
|
||||||
fn();
|
fn();
|
||||||
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
self.onException(e);
|
self.onException(e);
|
||||||
if (!self.catchException(e)) {
|
if (!self.catchException(e)) {
|
||||||
@@ -48,6 +49,7 @@ getJasmineRequireObj().QueueRunner = function() {
|
|||||||
//use a finally block to close the loop in a nice way..
|
//use a finally block to close the loop in a nice way..
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ getJasmineRequireObj().Suite = function() {
|
|||||||
children = this.children_;
|
children = this.children_;
|
||||||
|
|
||||||
for (var i = 0; i < children.length; i++) {
|
for (var i = 0; i < children.length; i++) {
|
||||||
allFns.push(wrapChild(children[i]));
|
allFns.push(wrapChildAsAsync(children[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.onStart(this);
|
this.onStart(this);
|
||||||
@@ -92,8 +92,8 @@ getJasmineRequireObj().Suite = function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function wrapChild(child) {
|
function wrapChildAsAsync(child) {
|
||||||
return function() { child.execute(); };
|
return function(done) { child.execute(done); };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user