Skip to content

Commit

Permalink
consider Node's exitCode
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Nov 22, 2019
1 parent 46ca9ac commit f90c624
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/cli/run-helpers.js
Expand Up @@ -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);
});
};

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

Expand Down

0 comments on commit f90c624

Please sign in to comment.