(hook: Function, result: any, context?: TestContext)
| 33 | const AROUND_STACK_TRACE_KEY = Symbol.for('VITEST_AROUND_STACK_TRACE') |
| 34 | |
| 35 | export function getBeforeHookCleanupCallback(hook: Function, result: any, context?: TestContext): Function | undefined { |
| 36 | if (typeof result === 'function') { |
| 37 | const timeout |
| 38 | = CLEANUP_TIMEOUT_KEY in hook && typeof hook[CLEANUP_TIMEOUT_KEY] === 'number' |
| 39 | ? hook[CLEANUP_TIMEOUT_KEY] |
| 40 | : getDefaultHookTimeout() |
| 41 | const stackTraceError |
| 42 | = CLEANUP_STACK_TRACE_KEY in hook && hook[CLEANUP_STACK_TRACE_KEY] instanceof Error |
| 43 | ? hook[CLEANUP_STACK_TRACE_KEY] |
| 44 | : undefined |
| 45 | return withTimeout( |
| 46 | result, |
| 47 | timeout, |
| 48 | true, |
| 49 | stackTraceError, |
| 50 | (_, error) => { |
| 51 | if (context) { |
| 52 | abortContextSignal(context, error) |
| 53 | } |
| 54 | }, |
| 55 | ) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Registers a callback function to be executed once before all tests within the current suite. |
no test coverage detected