(
timeout: number,
phase: 'setup' | 'teardown',
stackTraceError: Error | undefined,
)
| 274 | const hookErrors: unknown[] = [] |
| 275 | |
| 276 | const createTimeoutPromise = ( |
| 277 | timeout: number, |
| 278 | phase: 'setup' | 'teardown', |
| 279 | stackTraceError: Error | undefined, |
| 280 | ): { promise: Promise<never>; isTimedOut: () => boolean; clear: () => void } => { |
| 281 | let timer: ReturnType<typeof setTimeout> | undefined |
| 282 | let timedout = false |
| 283 | |
| 284 | const promise = new Promise<never>((_, reject) => { |
| 285 | if (timeout > 0 && timeout !== Number.POSITIVE_INFINITY) { |
| 286 | timer = setTimeout(() => { |
| 287 | timedout = true |
| 288 | const error = makeAroundHookTimeoutError(hookName, phase, timeout, stackTraceError) |
| 289 | onTimeout?.(error) |
| 290 | reject(error) |
| 291 | }, timeout) |
| 292 | timer.unref?.() |
| 293 | } |
| 294 | }) |
| 295 | |
| 296 | const clear = () => { |
| 297 | if (timer) { |
| 298 | clearTimeout(timer) |
| 299 | timer = undefined |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | return { promise, clear, isTimedOut: () => timedout } |
| 304 | } |
| 305 | |
| 306 | const runNextHook = async (index: number): Promise<void> => { |
| 307 | if (index >= hooks.length) { |
no test coverage detected