From d42e3fbf6d2c9d6b7e77e58295ddb7c38a984844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20R=C3=BC=C3=9Fler?= Date: Sun, 24 Dec 2023 11:53:34 +0100 Subject: [PATCH] Use NODE_ENV to detect Jest or Vitest --- packages/react/src/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/react/src/index.js b/packages/react/src/index.js index 3b4a3ad6a..7ce861cea 100644 --- a/packages/react/src/index.js +++ b/packages/react/src/index.js @@ -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