Skip to content
This repository has been archived by the owner on Mar 1, 2019. It is now read-only.

Commit

Permalink
tests: throw in case we encounter unhandled promise rejection
Browse files Browse the repository at this point in the history
As opposed to just showing a warning that might get eaten in cli when
multple jest child processes work in parallel.
See jestjs/jest#3251
This is a bit unsatifactory as it makes the parent jest process hang in
case there are such occurances.

Bug: T212409
  • Loading branch information
wiese authored and jakobw committed Dec 20, 2018
1 parent faf3dcc commit 35afe56
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/config/setup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
beforeEach( () => {
expect.hasAssertions();
} );

// Break on unhandled promise rejection (default warning might be overlooked)
// https://github.com/facebook/jest/issues/3251#issuecomment-299183885
// However...
// https://stackoverflow.com/questions/51957531/jest-how-to-throw-an-error-inside-a-unhandledrejection-handler
if ( typeof process.env.LISTENING_TO_UNHANDLED_REJECTION === 'undefined' ) {
process.on( 'unhandledRejection', ( unhandledRejectionWarning ) => {
throw unhandledRejectionWarning; // see stack trace for test at fault
} );
// Avoid memory leak by adding too many listeners
process.env.LISTENING_TO_UNHANDLED_REJECTION = 'yes';
}

0 comments on commit 35afe56

Please sign in to comment.