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 committed Apr 22, 2018
1 parent efff26f commit 85a36fd
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
Expand Up @@ -241,6 +241,9 @@ Runner.prototype.fail = function (test, err) {
}

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

/**
Expand Down Expand Up @@ -269,9 +272,6 @@ Runner.prototype.failHook = function (hook, err) {
hook.title = 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
@@ -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
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 85a36fd

Please sign in to comment.