Skip to content

Commit

Permalink
chore(web): better promise-rejection logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jahorton committed Jul 27, 2023
1 parent 287ba2c commit c6969b7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { assert } from 'chai'
import sinon from 'sinon';

import * as PromiseStatusModule from 'promise-status-async';
const promiseStatus = PromiseStatusModule.promiseStatus;
const PromiseStatuses = PromiseStatusModule.PromiseStatuses;
import { assertingPromiseStatus as promiseStatus } from '../../../resources/assertingPromiseStatus.js';

import { ComplexGestureSource, InputSample, SimpleGestureSource, gestures } from '@keymanapp/gesture-recognizer';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { assert } from 'chai'
import sinon from 'sinon';

import * as PromiseStatusModule from 'promise-status-async';
const promiseStatus = PromiseStatusModule.promiseStatus;
const PromiseStatuses = PromiseStatusModule.PromiseStatuses;
import { assertingPromiseStatus as promiseStatus } from '../../../resources/assertingPromiseStatus.js';

import { InputSample, SimpleGestureSource, gestures } from '@keymanapp/gesture-recognizer';
import { timedPromise } from '@keymanapp/web-utils';
Expand Down
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;
}

0 comments on commit c6969b7

Please sign in to comment.