Skip to content

Commit fbb1468

Browse files
authoredApr 27, 2023
fix: throw an error if Vitest cannot access its internal state (#3250)
1 parent c759a9a commit fbb1468

File tree

1 file changed

+10
-0
lines changed
  • packages/vitest/src/integrations

1 file changed

+10
-0
lines changed
 

‎packages/vitest/src/integrations/vi.ts

+10
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ function createVitest(): VitestUtils {
168168
let _config: null | ResolvedConfig = null
169169

170170
const workerState = getWorkerState()
171+
172+
if (!workerState) {
173+
const errorMsg = 'Vitest failed to access its internal state.'
174+
+ '\n\nOne of the following is possible:'
175+
+ '\n- "vitest" is imported directly without running "vitest" command'
176+
+ '\n- "vitest" is imported inside "globalSetup" (to fix this, use "setupFiles" instead, because "globalSetup" runs in a different context)'
177+
+ '\n- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n'
178+
throw new Error(errorMsg)
179+
}
180+
171181
const _timers = new FakeTimers({
172182
global: globalThis,
173183
config: workerState.config.fakeTimers,

0 commit comments

Comments
 (0)
Please sign in to comment.