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

Use NODE_ENV to detect Jest or Vitest #3144

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/react/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export { default as css } from './css'
if (process.env.NODE_ENV !== 'production') {
const isBrowser = typeof document !== 'undefined'
// #1727, #2905 for some reason Jest and Vitest evaluate modules twice if some consuming module gets mocked
const isTestEnv = typeof jest !== 'undefined' || typeof vi !== 'undefined'
// Both Jest as well as Vitest set `process.env.NODE_ENV` to `'test'`, according to their docs.
// https://jestjs.io/docs/environment-variables#node_env
// https://vitest.dev/guide/migration.html#envs
const isTestEnv = process.env.NODE_ENV === 'test'

if (isBrowser && !isTestEnv) {
// globalThis has wide browser support - https://caniuse.com/?search=globalThis, Node.js 12 and later
Expand Down
Loading