Skip to content

Commit 10ff0ec

Browse files
chrisleckdasilvacontin
authored andcommitted
Eagerly set process.exitCode (#2820)
To workaround process being terminated earlier than expected. Simpler version of PR #2714 which only eagerly sets the exitcode without playing with the draining semantics.
1 parent fc35691 commit 10ff0ec

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

bin/_mocha

+7-1
Original file line numberDiff line numberDiff line change
@@ -476,12 +476,18 @@ function exitLater (code) {
476476
}
477477

478478
function exit (code) {
479+
var clampedCode = Math.min(code, 255);
480+
481+
// Eagerly set the process's exit code in case stream.write doesn't
482+
// execute its callback before the process terminates.
483+
process.exitCode = clampedCode;
484+
479485
// flush output for Node.js Windows pipe bug
480486
// https://github.com/joyent/node/issues/6247 is just one bug example
481487
// https://github.com/visionmedia/mocha/issues/333 has a good discussion
482488
function done () {
483489
if (!(draining--)) {
484-
process.exit(Math.min(code, 255));
490+
process.exit(clampedCode);
485491
}
486492
}
487493

0 commit comments

Comments
 (0)