MCPcopy
hub / github.com/vitest-dev/vitest / getBeforeHookCleanupCallback

Function getBeforeHookCleanupCallback

packages/runner/src/hooks.ts:35–57  ·  view source on GitHub ↗
(hook: Function, result: any, context?: TestContext)

Source from the content-addressed store, hash-verified

33const AROUND_STACK_TRACE_KEY = Symbol.for('VITEST_AROUND_STACK_TRACE')
34
35export 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.

Callers 1

runHookFunction · 0.90

Calls 3

withTimeoutFunction · 0.90
abortContextSignalFunction · 0.90
getDefaultHookTimeoutFunction · 0.85

Tested by

no test coverage detected