Skip to content

Commit

Permalink
fix to exit correctly when using bail flag
Browse files Browse the repository at this point in the history
  • Loading branch information
outsideris authored and boneskull committed May 18, 2018
1 parent d87b12e commit 3ab0e7e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ Runner.prototype.fail = function(test, err) {
}

this.emit('fail', test, err);
if (this.suite.bail()) {
this.emit('end');
}
};

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

if (this.suite.bail()) {
this.emit('end');
}
this.fail(hook, err);
};

Expand Down
11 changes: 11 additions & 0 deletions test/integration/fixtures/options/bail-with-before.fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

describe('suite1', function () {
before(function () {
throw new Error('this hook should be only displayed');
});

it('should not display this error', function () {
throw new Error('this should not be displayed');
});
});
16 changes: 16 additions & 0 deletions test/integration/options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ describe('options', function() {
});
});

it('should stop all tests after the first error in before hook', function(done) {
run('options/bail-with-before.fixture.js', args, function(err, res) {
if (err) {
done(err);
return;
}
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 0);
assert.equal(res.stats.failures, 1);

assert.equal(res.failures[0].title, '"before all" hook');
assert.equal(res.code, 1);
done();
});
});

it('should stop all hooks after the first error', function(done) {
run('options/bail-with-after.fixture.js', args, function(err, res) {
if (err) {
Expand Down

0 comments on commit 3ab0e7e

Please sign in to comment.