Skip to content

Commit

Permalink
fix(browser): throw an error if "@vitest/browser/context" is imported…
Browse files Browse the repository at this point in the history
… outside of the browser mode
  • Loading branch information
sheremet-va committed Sep 25, 2024
1 parent f8ff76a commit 67fb56b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/browser/context.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
// empty file to not break bundling
// Vitest resolves "@vitest/browser/context" as a virtual module instead

// fake exports for static analysis
export const page = null
export const server = null
export const userEvent = null
export const cdp = null
export const commands = null

const pool = globalThis.__vitest_worker__?.ctx?.pool

throw new Error(
// eslint-disable-next-line prefer-template
'@vitest/browser/context can be imported only inside the Browser Mode. '
+ (pool
? `Your test is running in ${pool} pool. Make sure your regular tests are excluded from the "test.include" glob pattern.`
: 'Instead, it was imported outside of Vitest.'),
)

0 comments on commit 67fb56b

Please sign in to comment.