Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix to exit correctly when using bail flag #3346

Merged
merged 1 commit into from Apr 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/runner.js
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
@@ -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