Skip to content

Commit 9f229c1

Browse files
Liviu RauDevtools-frontend LUCI CQ
authored andcommitted
Increase type safety
Proposed at https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6278526/comment/030169e5_9ad30f4e/ Bug: none Change-Id: I94b2b34df89431cff4128143fc4421e7e9ed842e Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6322271 Auto-Submit: Liviu Rau <[email protected]> Reviewed-by: Nikolay Vitkov <[email protected]> Reviewed-by: Alex Rudenko <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]>
1 parent 628109e commit 9f229c1

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

test/e2e_non_hosted/conductor/mocha-interface-helpers.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,7 @@ async function createScreenshotError(test: Mocha.Runnable|undefined, error: Erro
6767
export function makeInstrumentedTestFunction(fn: Mocha.AsyncFunc, label: string) {
6868
return async function testFunction(this: Mocha.Context) {
6969
const abortController = new AbortController();
70-
let resolver;
71-
let rejecter: (reason?: unknown) => void;
72-
const testPromise = new Promise((resolve, reject) => {
73-
resolver = resolve;
74-
rejecter = reject;
75-
});
70+
const {promise: testPromise, resolve, reject} = Promise.withResolvers<unknown>();
7671
// AbortSignal for the current test function.
7772
AsyncScope.abortSignal = abortController.signal;
7873
// Promisify the function in case it is sync.
@@ -96,17 +91,17 @@ export function makeInstrumentedTestFunction(fn: Mocha.AsyncFunc, label: string)
9691
const msg = `Pending async operations during timeout:\n${stacks.join('\n\n')}`;
9792
err.cause = new Error(msg);
9893
}
99-
rejecter(await createScreenshotError(this.test, err));
94+
reject(await createScreenshotError(this.test, err));
10095
}, actualTimeout) : 0;
10196
promise
10297
.then(
103-
resolver,
98+
resolve,
10499
async err => {
105100
// Suppress errors after the test was aborted.
106101
if (abortController.signal.aborted) {
107102
return;
108103
}
109-
rejecter(await createScreenshotError(this.test, err));
104+
reject(await createScreenshotError(this.test, err));
110105
})
111106
.finally(() => {
112107
clearTimeout(t);

0 commit comments

Comments
 (0)