()
| 9 | } |
| 10 | |
| 11 | export 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 | |
| 27 | export function getSafeWorkerState(): WorkerGlobalState | undefined { |
| 28 | // @ts-expect-error untyped global |
no outgoing calls
no test coverage detected