Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ if (mochaArgs['node-option'] || Object.keys(nodeArgs).length || hasInspect) {
process.kill(process.pid, signal);
}
} else {
process.exit(code);
process.exit((mochaArgs['posix-exit-codes'] === true) ? 0 : code);
}
});
});
Expand Down
27 changes: 25 additions & 2 deletions test/integration/options/posixExitCodes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var helpers = require('../helpers');
var runMocha = helpers.runMocha;

describe('--posix-exit-codes', function () {
describe('when enabled with node options', function () {
describe('when enabled, and with node options', function () {
var args = ['--no-warnings', '--posix-exit-codes'];

it('should exit with code 134 on SIGABRT', function (done) {
Expand All @@ -28,9 +28,20 @@ describe('--posix-exit-codes', function () {
done();
});
});

it('should exit with code 0 even if there are test failures', function (done) {
var fixture = 'failing.fixture.js';
runMocha(fixture, args, function postmortem(err, res) {
if (err) {
return done(err);
}
expect(res.code, 'to be', 0);
done();
});
});
});

describe('when not enabled with node options', function () {
describe('when not enabled, and with node options', function () {
it('should exit with code null on SIGABRT', function (done) {
var fixture = 'signals-sigabrt.fixture.js';
var args = ['--no-warnings'];
Expand All @@ -42,5 +53,17 @@ describe('--posix-exit-codes', function () {
done();
});
});

it('should exit with the number of failed tests', function (done) {
var fixture = 'failing.fixture.js'; // one failing test
var args = ['--no-warnings'];
runMocha(fixture, args, function postmortem(err, res) {
if (err) {
return done(err);
}
expect(res.code, 'to be', 1);
done();
});
});
});
});