From f90c624dd02e6da9903ac55d76f17b78ca60f2dc Mon Sep 17 00:00:00 2001 From: juergba Date: Fri, 22 Nov 2019 19:06:00 +0100 Subject: [PATCH] consider Node's exitCode --- lib/cli/run-helpers.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/cli/run-helpers.js b/lib/cli/run-helpers.js index 6c662a665f..458ba0c8c4 100644 --- a/lib/cli/run-helpers.js +++ b/lib/cli/run-helpers.js @@ -25,7 +25,8 @@ exports.watchRun = watchRun; */ const exitMochaLater = code => { process.on('exit', () => { - process.exitCode = Math.min(code, 255); + // keep exitCode set by Node (eg. uncaughtException) + process.exitCode = process.exitCode || Math.min(code, 255); }); }; @@ -37,19 +38,15 @@ const exitMochaLater = code => { * @private */ const exitMocha = code => { - const clampedCode = Math.min(code, 255); + process.exitCode = process.exitCode || Math.min(code, 255); let draining = 0; - // Eagerly set the process's exit code in case stream.write doesn't - // execute its callback before the process terminates. - process.exitCode = clampedCode; - // flush output for Node.js Windows pipe bug // https://github.com/joyent/node/issues/6247 is just one bug example // https://github.com/visionmedia/mocha/issues/333 has a good discussion const done = () => { if (!draining--) { - process.exit(clampedCode); + process.exit(); } };