Skip to content

Commit 99c2f8a

Browse files
outsiderisboneskull
authored andcommitted
fix to exit correctly when using bail flag
1 parent 1224a48 commit 99c2f8a

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

lib/runner.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ Runner.prototype.fail = function(test, err) {
249249
}
250250

251251
this.emit('fail', test, err);
252+
if (this.suite.bail()) {
253+
this.emit('end');
254+
}
252255
};
253256

254257
/**
@@ -278,9 +281,6 @@ Runner.prototype.failHook = function(hook, err) {
278281
hook.originalTitle + ' for "' + hook.ctx.currentTest.title + '"';
279282
}
280283

281-
if (this.suite.bail()) {
282-
this.emit('end');
283-
}
284284
this.fail(hook, err);
285285
};
286286

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
describe('suite1', function () {
4+
before(function () {
5+
throw new Error('this hook should be only displayed');
6+
});
7+
8+
it('should not display this error', function () {
9+
throw new Error('this should not be displayed');
10+
});
11+
});

test/integration/options.spec.js

+16
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ describe('options', function() {
6969
});
7070
});
7171

72+
it('should stop all tests after the first error in before hook', function(done) {
73+
run('options/bail-with-before.fixture.js', args, function(err, res) {
74+
if (err) {
75+
done(err);
76+
return;
77+
}
78+
assert.equal(res.stats.pending, 0);
79+
assert.equal(res.stats.passes, 0);
80+
assert.equal(res.stats.failures, 1);
81+
82+
assert.equal(res.failures[0].title, '"before all" hook');
83+
assert.equal(res.code, 1);
84+
done();
85+
});
86+
});
87+
7288
it('should stop all hooks after the first error', function(done) {
7389
run('options/bail-with-after.fixture.js', args, function(err, res) {
7490
if (err) {

0 commit comments

Comments
 (0)