Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Commit

Permalink
Exit process with correct error codes (mochajs#2445)
Browse files Browse the repository at this point in the history
* Exit with code 130 in SIGINT. Refs mochajs#2438

* Exit with code 255 if more errors than 255 were returned. Fixes mochajs#2438
  • Loading branch information
Munter authored and boneskull committed Sep 18, 2016
1 parent 9f82ec8 commit 79f61a4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions bin/_mocha
Expand Up @@ -384,7 +384,7 @@ if (program.watch) {
process.on('SIGINT', function() {
showCursor();
console.log('\n');
process.exit();
process.exit(130);
});

var watchFiles = utils.files(cwd, [ 'js' ].concat(program.watchExtensions));
Expand Down Expand Up @@ -442,7 +442,7 @@ if (program.watch) {

function exitLater(code) {
process.on('exit', function() {
process.exit(code);
process.exit(Math.min(code, 255));
});
}

Expand All @@ -452,7 +452,7 @@ function exit(code) {
// https://github.com/visionmedia/mocha/issues/333 has a good discussion
function done() {
if (!(draining--)) {
process.exit(code);
process.exit(Math.min(code, 255));
}
}

Expand All @@ -470,6 +470,11 @@ function exit(code) {

process.on('SIGINT', function() {
runner.abort();

// This is a hack:
// Instead of `process.exit(130)`, set runner.failures to 130 (exit code for SIGINT)
// The amount of failures will be emitted as error code later
runner.failures = 130;
});

/**
Expand Down

0 comments on commit 79f61a4

Please sign in to comment.