Skip to content

Commit

Permalink
exit code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Sep 16, 2019
1 parent 123a0d7 commit 8c68fe5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/cli/run-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ exports.watchRun = watchRun;
*/
const exitMochaLater = code => {
process.on('exit', () => {
process.exitCode = Math.min(code, 255);
// when uncaught error, keep exitCode 1
if (!process.exitCode) {
process.exitCode = Math.min(code, 255);
}
});
};

Expand Down
7 changes: 7 additions & 0 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,9 +786,16 @@ Runner.prototype.runSuite = function(suite, fn) {
* @private
*/
Runner.prototype.uncaught = function(err) {
// 'this.skip()' aborts hook/test execution by throwing an exception
if (err instanceof Pending) {
return;
}
// allow uncaught exceptions to propagate and exit
if (this.allowUncaught) {
console.error('\n', err);
process.exit(1);
}

if (err) {
debug('uncaught exception %O', err);
} else {
Expand Down

0 comments on commit 8c68fe5

Please sign in to comment.