Skip to content

Commit

Permalink
fix: throw an error if Vitest cannot access its internal state (#3250)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Apr 27, 2023
1 parent c759a9a commit fbb1468
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/vitest/src/integrations/vi.ts
Expand Up @@ -168,6 +168,16 @@ function createVitest(): VitestUtils {
let _config: null | ResolvedConfig = null

const workerState = getWorkerState()

if (!workerState) {
const errorMsg = 'Vitest failed to access its internal state.'
+ '\n\nOne of the following is possible:'
+ '\n- "vitest" is imported directly without running "vitest" command'
+ '\n- "vitest" is imported inside "globalSetup" (to fix this, use "setupFiles" instead, because "globalSetup" runs in a different context)'
+ '\n- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n'
throw new Error(errorMsg)
}

const _timers = new FakeTimers({
global: globalThis,
config: workerState.config.fakeTimers,
Expand Down

0 comments on commit fbb1468

Please sign in to comment.