Skip to content

Commit 3e22a83

Browse files
Munterboneskull
authored andcommitted
Exit process with correct error codes (#2445)
* Exit with code 130 in SIGINT. Refs #2438 * Exit with code 255 if more errors than 255 were returned. Fixes #2438
1 parent 5e1cd44 commit 3e22a83

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

bin/_mocha

+8-3
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ if (program.watch) {
384384
process.on('SIGINT', function() {
385385
showCursor();
386386
console.log('\n');
387-
process.exit();
387+
process.exit(130);
388388
});
389389

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

443443
function exitLater(code) {
444444
process.on('exit', function() {
445-
process.exit(code);
445+
process.exit(Math.min(code, 255));
446446
});
447447
}
448448

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

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

471471
process.on('SIGINT', function() {
472472
runner.abort();
473+
474+
// This is a hack:
475+
// Instead of `process.exit(130)`, set runner.failures to 130 (exit code for SIGINT)
476+
// The amount of failures will be emitted as error code later
477+
runner.failures = 130;
473478
});
474479

475480
/**

0 commit comments

Comments
 (0)