Skip to content

Commit 3c668d2

Browse files
fix: testrunner timeouts
1 parent 72581f4 commit 3c668d2

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

vendor/testrunner/testRunner.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,20 @@ function afterEach(fn: HookFunction) {
8787
* @param timeout - The timeout in milliseconds.
8888
* @returns A promise that resolves if the function completes in time, or rejects if it times out.
8989
*/
90-
function runWithTimeout(fn: Function, timeout: number): Promise<void> {
91-
return Promise.race([
90+
async function runWithTimeout(fn: Function, timeout: number): Promise<void> {
91+
let timeoutHandle: ReturnType<typeof setTimeout> | undefined
92+
const res = await Promise.race([
9293
fn(),
93-
new Promise((_, reject) => setTimeout(() => reject(new Error(`Timeout of ${timeout}ms exceeded`)), timeout)),
94+
new Promise((_, reject) => {
95+
timeoutHandle = setTimeout(() => reject(new Error(`Timeout of ${timeout}ms exceeded`)), timeout)
96+
}),
9497
])
98+
99+
if (timeoutHandle) {
100+
clearTimeout(timeoutHandle)
101+
timeoutHandle = undefined
102+
}
103+
return res
95104
}
96105

97106
/**

0 commit comments

Comments
 (0)