diff --git a/.changeset/loud-dancers-return.md b/.changeset/loud-dancers-return.md new file mode 100644 index 000000000..c0a93cf7e --- /dev/null +++ b/.changeset/loud-dancers-return.md @@ -0,0 +1,5 @@ +--- +'@emotion/react': patch +--- + +Do not warn about `@emotion/react` being loaded twice in Vitest as that might easily happen with mocked modules. diff --git a/flow-typed/npm/vitest_vx.x.x.js b/flow-typed/npm/vitest_vx.x.x.js new file mode 100644 index 000000000..4fbf0e5de --- /dev/null +++ b/flow-typed/npm/vitest_vx.x.x.js @@ -0,0 +1 @@ +declare var vi: {} diff --git a/packages/react/src/index.js b/packages/react/src/index.js index 24323ed22..3b4a3ad6a 100644 --- a/packages/react/src/index.js +++ b/packages/react/src/index.js @@ -16,10 +16,10 @@ export { default as css } from './css' if (process.env.NODE_ENV !== 'production') { const isBrowser = typeof document !== 'undefined' - // #1727 for some reason Jest evaluates modules twice if some consuming module gets mocked with jest.mock - const isJest = typeof jest !== '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' - if (isBrowser && !isJest) { + if (isBrowser && !isTestEnv) { // globalThis has wide browser support - https://caniuse.com/?search=globalThis, Node.js 12 and later const globalContext = // $FlowIgnore