-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(browser): throw an error if "@vitest/browser/context" is imported…
… outside of the browser mode (#6570)
- Loading branch information
1 parent
821400b
commit 383f179
Showing
4 changed files
with
24 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.'), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { page } from '@vitest/browser/context' | ||
|
||
console.log(page) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters