Skip to content

Commit

Permalink
fix to bail option works properly with hooks (#3278)
Browse files Browse the repository at this point in the history
  • Loading branch information
outsideris authored Mar 20, 2018
1 parent 0060884 commit 6383916
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

/**
Expand Down
11 changes: 11 additions & 0 deletions test/integration/fixtures/options/bail-with-after.fixture.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
16 changes: 16 additions & 0 deletions test/integration/options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 6383916

Please sign in to comment.