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

Function getWorkerState

packages/vitest/src/runtime/utils.ts:11–25  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9}
10
11export function getWorkerState(): WorkerGlobalState {
12 // @ts-expect-error untyped global
13 const workerState = globalThis[NAME_WORKER_STATE]
14 if (!workerState) {
15 const errorMsg
16 = 'Vitest failed to access its internal state.'
17 + '\n\nOne of the following is possible:'
18 + '\n- "vitest" is imported directly without running "vitest" command'
19 + '\n- "vitest" is imported inside "globalSetup" (to fix this, use "setupFiles" instead, because "globalSetup" runs in a different context)'
20 + '\n- "vitest" is imported inside Vite / Vitest config file'
21 + '\n- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n'
22 throw new Error(errorMsg)
23 }
24 return workerState
25}
26
27export function getSafeWorkerState(): WorkerGlobalState | undefined {
28 // @ts-expect-error untyped global

Callers 15

stateFunction · 0.90
injectFunction · 0.90
testPathFunction · 0.90
createExpectPollFunction · 0.90
assertMatchResultFunction · 0.90
resolvePathMethod · 0.90
stateFunction · 0.90
runFunction · 0.90
runFunction · 0.90
benchmark.tsFile · 0.90
rpcFunction · 0.90
setupEnvFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected