From 79f61a429ba7a67eaf90871ad40b47d6eafd6d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20M=C3=BCller?= Date: Sun, 18 Sep 2016 23:48:15 +0200 Subject: [PATCH] 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 --- bin/_mocha | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bin/_mocha b/bin/_mocha index 98cabdbc47..fe3f67861a 100755 --- a/bin/_mocha +++ b/bin/_mocha @@ -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)); @@ -442,7 +442,7 @@ if (program.watch) { function exitLater(code) { process.on('exit', function() { - process.exit(code); + process.exit(Math.min(code, 255)); }); } @@ -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)); } } @@ -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; }); /**