From c5a1d38e5ea821eb320dad24558534b171173161 Mon Sep 17 00:00:00 2001 From: Outsider Date: Sun, 11 Mar 2018 23:44:09 +0900 Subject: [PATCH] fix to bail option works properly with hooks --- lib/runner.js | 2 +- .../fixtures/options/bail-with-after.fixture.js | 11 +++++++++++ test/integration/options.spec.js | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 test/integration/fixtures/options/bail-with-after.fixture.js 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..cd6fd00798 --- /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 (done) { + throw new Error('this should be displayed'); + }); + + after(function (done) { + 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 () {