-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(web): better promise-rejection logging
- Loading branch information
Showing
3 changed files
with
21 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
common/web/gesture-recognizer/src/test/resources/assertingPromiseStatus.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as PromiseStatusModule from 'promise-status-async'; | ||
|
||
/** | ||
* A custom variant of the promise-status function; this one asserts that rejections should | ||
* be reported as test errors. If a rejection occurs, it will ensure that it is reported | ||
* on the main thread / error output. | ||
* @param promise | ||
* @returns | ||
*/ | ||
export async function assertingPromiseStatus(promise: Promise<any>) { | ||
const status = await PromiseStatusModule.promiseStatus(promise); | ||
if(status == PromiseStatusModule.PROMISE_REJECTED) { | ||
// Synchronize on the spot - this will cause the calling test to throw and report | ||
// the reported rejection cause / error. This is far more informative in error logs | ||
// than "oh, the promise was rejected" - with no indication as to _why_. | ||
await promise; | ||
} | ||
return status; | ||
} |