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(); } };