Skip to content

Commit

Permalink
Do not warn about @emotion/react being loaded twice in Vitest (#2905)
Browse files Browse the repository at this point in the history
* Check vitest global for @emotion/react loaded twice warning

* code review tweaks

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
  • Loading branch information
p-m-p and Andarist authored Oct 27, 2022
1 parent 61c6696 commit 4c0005f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-dancers-return.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions flow-typed/npm/vitest_vx.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare var vi: {}
6 changes: 3 additions & 3 deletions packages/react/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4c0005f

Please sign in to comment.