diff --git a/lib/runner.js b/lib/runner.js index 5a7e3e03e0..bc4d6523dd 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -265,10 +265,10 @@ Runner.prototype.failHook = function (hook, err) { hook.title = hook.originalTitle + ' for "' + hook.ctx.currentTest.title + '"'; } - this.fail(hook, err); if (this.suite.bail()) { this.emit('end'); } + this.fail(hook, err); }; /** diff --git a/test/integration/fixtures/options/bail-with-after.fixture.js b/test/integration/fixtures/options/bail-with-after.fixture.js new file mode 100644 index 0000000000..f722092924 --- /dev/null +++ b/test/integration/fixtures/options/bail-with-after.fixture.js @@ -0,0 +1,11 @@ +'use strict'; + +describe('suite1', function () { + it('should only display this error', function () { + throw new Error('this should be displayed'); + }); + + after(function () { + throw new Error('this hook should not be displayed'); + }); +}); diff --git a/test/integration/options.spec.js b/test/integration/options.spec.js index 6c7390c0c2..a010572821 100644 --- a/test/integration/options.spec.js +++ b/test/integration/options.spec.js @@ -68,6 +68,22 @@ describe('options', function () { 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) { + 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, 'should only display this error'); + assert.equal(res.code, 1); + done(); + }); + }); }); describe('--sort', function () {