From 4c0005f677d5847e7f931a1473ac58b834606c57 Mon Sep 17 00:00:00 2001 From: Phil Parsons Date: Thu, 27 Oct 2022 08:35:51 +0100 Subject: [PATCH] Do not warn about `@emotion/react` being loaded twice in Vitest (#2905) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Check vitest global for @emotion/react loaded twice warning * code review tweaks Co-authored-by: Mateusz BurzyƄski --- .changeset/loud-dancers-return.md | 5 +++++ flow-typed/npm/vitest_vx.x.x.js | 1 + packages/react/src/index.js | 6 +++--- 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 .changeset/loud-dancers-return.md create mode 100644 flow-typed/npm/vitest_vx.x.x.js 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