Skip to content

Commit

Permalink
Use NODE_ENV to detect Jest or Vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
cruessler committed Dec 24, 2023
1 parent b0014b4 commit d42e3fb
Showing 1 changed file with 4 additions and 1 deletion.
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

0 comments on commit d42e3fb

Please sign in to comment.