Skip to content

Commit 4c0005f

Browse files
p-m-pAndarist
andauthored
Do not warn about @emotion/react being loaded twice in Vitest (emotion-js#2905)
* Check vitest global for @emotion/react loaded twice warning * code review tweaks Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
1 parent 61c6696 commit 4c0005f

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

.changeset/loud-dancers-return.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@emotion/react': patch
3+
---
4+
5+
Do not warn about `@emotion/react` being loaded twice in Vitest as that might easily happen with mocked modules.

flow-typed/npm/vitest_vx.x.x.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare var vi: {}

packages/react/src/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ export { default as css } from './css'
1616

1717
if (process.env.NODE_ENV !== 'production') {
1818
const isBrowser = typeof document !== 'undefined'
19-
// #1727 for some reason Jest evaluates modules twice if some consuming module gets mocked with jest.mock
20-
const isJest = typeof jest !== 'undefined'
19+
// #1727, #2905 for some reason Jest and Vitest evaluate modules twice if some consuming module gets mocked
20+
const isTestEnv = typeof jest !== 'undefined' || typeof vi !== 'undefined'
2121

22-
if (isBrowser && !isJest) {
22+
if (isBrowser && !isTestEnv) {
2323
// globalThis has wide browser support - https://caniuse.com/?search=globalThis, Node.js 12 and later
2424
const globalContext =
2525
// $FlowIgnore

0 commit comments

Comments
 (0)