Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: throw an error if Vitest cannot access its internal state #3250

Merged
merged 2 commits into from Apr 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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