Skip to content

Commit 8f7327c

Browse files
author
Gregg Van Hove
committed
Properly cascade StopExecutionError's up the tree
- Fixes jasmine#1563
1 parent 3636014 commit 8f7327c

File tree

6 files changed

+55
-11
lines changed

6 files changed

+55
-11
lines changed

lib/jasmine-core/jasmine.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -4913,7 +4913,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
49134913
return;
49144914
}
49154915

4916-
self.errored = result.errored;
4916+
self.errored = self.errored || result.errored;
49174917

49184918
if (this.completeOnFirstError && result.errored) {
49194919
this.skipToCleanup(iterativeIndex);
@@ -6265,8 +6265,11 @@ getJasmineRequireObj().TreeProcessor = function() {
62656265

62666266
queueRunnerFactory({
62676267
onComplete: function () {
6268+
var args = Array.prototype.slice.call(arguments, [0]);
62686269
node.cleanupBeforeAfter();
6269-
nodeComplete(node, node.getResult(), done);
6270+
nodeComplete(node, node.getResult(), function() {
6271+
done.apply(undefined, args);
6272+
});
62706273
},
62716274
queueableFns: [onStart].concat(wrapChildren(node, segmentNumber)),
62726275
userContext: node.sharedUserContext(),

spec/core/QueueRunnerSpec.js

+3
Original file line numberDiff line numberDiff line change
@@ -481,15 +481,18 @@ describe("QueueRunner", function() {
481481
var queueableFn = { fn: function() { throw new Error("error"); } },
482482
nextQueueableFn = { fn: jasmine.createSpy("nextFunction") },
483483
cleanupFn = { fn: jasmine.createSpy("cleanup") },
484+
onComplete = jasmine.createSpy("onComplete"),
484485
queueRunner = new jasmineUnderTest.QueueRunner({
485486
queueableFns: [queueableFn, nextQueueableFn],
486487
cleanupFns: [cleanupFn],
488+
onComplete: onComplete,
487489
completeOnFirstError: true
488490
});
489491

490492
queueRunner.execute();
491493
expect(nextQueueableFn.fn).not.toHaveBeenCalled();
492494
expect(cleanupFn.fn).toHaveBeenCalled();
495+
expect(onComplete).toHaveBeenCalledWith(jasmine.any(jasmineUnderTest.StopExecutionError));
493496
});
494497

495498
it("does not skip when a cleanup function throws", function() {

spec/core/TreeProcessorSpec.js

+33-2
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ describe("TreeProcessor", function() {
297297
node.getResult.and.returnValue({ my: 'result' });
298298

299299
queueRunner.calls.mostRecent().args[0].onComplete();
300-
expect(nodeComplete).toHaveBeenCalledWith(node, { my: 'result' }, nodeDone);
300+
expect(nodeComplete).toHaveBeenCalledWith(node, { my: 'result' }, jasmine.any(Function));
301301
});
302302

303303
it("runs a node with children", function() {
@@ -328,6 +328,37 @@ describe("TreeProcessor", function() {
328328
expect(leaf2.execute).toHaveBeenCalledWith('bar', false);
329329
});
330330

331+
it("cascades errors up the tree", function() {
332+
var leaf = new Leaf(),
333+
node = new Node({ children: [leaf] }),
334+
root = new Node({ children: [node] }),
335+
queueRunner = jasmine.createSpy('queueRunner'),
336+
nodeComplete = jasmine.createSpy('nodeComplete'),
337+
processor = new jasmineUnderTest.TreeProcessor({
338+
tree: root,
339+
runnableIds: [node.id],
340+
nodeComplete: nodeComplete,
341+
queueRunnerFactory: queueRunner
342+
}),
343+
treeComplete = jasmine.createSpy('treeComplete'),
344+
nodeDone = jasmine.createSpy('nodeDone');
345+
346+
processor.execute(treeComplete);
347+
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
348+
queueableFns[0].fn(nodeDone);
349+
350+
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
351+
expect(queueableFns.length).toBe(2);
352+
353+
queueableFns[1].fn('foo');
354+
expect(leaf.execute).toHaveBeenCalledWith('foo', false);
355+
356+
queueRunner.calls.mostRecent().args[0].onComplete('things');
357+
expect(nodeComplete).toHaveBeenCalled();
358+
nodeComplete.calls.mostRecent().args[2]();
359+
expect(nodeDone).toHaveBeenCalledWith('things');
360+
});
361+
331362
it("runs an excluded node with leaf", function() {
332363
var leaf1 = new Leaf(),
333364
node = new Node({ children: [leaf1] }),
@@ -361,7 +392,7 @@ describe("TreeProcessor", function() {
361392
node.getResult.and.returnValue({ im: 'disabled' });
362393

363394
queueRunner.calls.mostRecent().args[0].onComplete();
364-
expect(nodeComplete).toHaveBeenCalledWith(node, { im: 'disabled' }, nodeDone);
395+
expect(nodeComplete).toHaveBeenCalledWith(node, { im: 'disabled' }, jasmine.any(Function));
365396
});
366397

367398
it("runs beforeAlls for a node with children", function() {

spec/core/integration/SpecRunningSpec.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -952,13 +952,17 @@ describe("spec running", function () {
952952
it("does not run further specs when one fails", function(done) {
953953
var actions = [];
954954

955-
env.it('fails', function() {
956-
actions.push('fails');
957-
env.expect(1).toBe(2);
955+
env.describe('wrapper', function() {
956+
env.it('fails', function() {
957+
actions.push('fails');
958+
env.expect(1).toBe(2);
959+
});
958960
});
959961

960-
env.it('does not run', function() {
961-
actions.push('does not run');
962+
env.describe('holder', function() {
963+
env.it('does not run', function() {
964+
actions.push('does not run');
965+
});
962966
});
963967

964968
env.randomizeTests(false);

src/core/QueueRunner.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
159159
return;
160160
}
161161

162-
self.errored = result.errored;
162+
self.errored = self.errored || result.errored;
163163

164164
if (this.completeOnFirstError && result.errored) {
165165
this.skipToCleanup(iterativeIndex);

src/core/TreeProcessor.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,11 @@ getJasmineRequireObj().TreeProcessor = function() {
174174

175175
queueRunnerFactory({
176176
onComplete: function () {
177+
var args = Array.prototype.slice.call(arguments, [0]);
177178
node.cleanupBeforeAfter();
178-
nodeComplete(node, node.getResult(), done);
179+
nodeComplete(node, node.getResult(), function() {
180+
done.apply(undefined, args);
181+
});
179182
},
180183
queueableFns: [onStart].concat(wrapChildren(node, segmentNumber)),
181184
userContext: node.sharedUserContext(),

0 commit comments

Comments
 (0)