Skip to content

Commit

Permalink
Merge pull request #706 from appfolio/deUnhandledRejection
Browse files Browse the repository at this point in the history
Handle unhandled promise rejections
  • Loading branch information
gthomas-appfolio committed Jun 12, 2020
2 parents 039ca6a + 631abde commit b24d824
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,19 @@ global.requestAnimationFrame = (cb) => {
};

global.cancelAnimationFrame = () => {};

// Throw exceptions on unhandled promise rejections to prevent tests
// from silently failing async. In the future mocha might handle this
// automatically for us
//
let unhandledRejection = false;
process.on('unhandledRejection', (reason, promise) => {
console.error('unhandled rejection:', reason || promise); // eslint-disable-line no-console
unhandledRejection = true;
throw promise;
});
process.prependListener('exit', (code) => {
if (unhandledRejection && code === 0) {
process.exit(1);
}
});

0 comments on commit b24d824

Please sign in to comment.