From 7148a7f40192eec2b6c0b42cb549a7b1be643c89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20M=C3=BCller?= Date: Mon, 15 Aug 2016 23:58:03 +0200 Subject: [PATCH 1/2] Exit with code 130 in SIGINT. Refs #2438 --- bin/_mocha | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/_mocha b/bin/_mocha index 98cabdbc47..753fd8ca77 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)); @@ -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; }); /** From 758f4125a65fde41a501cfe891d0a5e7cd3ac965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20M=C3=BCller?= Date: Mon, 15 Aug 2016 23:59:04 +0200 Subject: [PATCH 2/2] Exit with code 255 if more errors than 255 were returned. Fixes #2438 --- bin/_mocha | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/_mocha b/bin/_mocha index 753fd8ca77..fe3f67861a 100755 --- a/bin/_mocha +++ b/bin/_mocha @@ -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)); } }