From 8a8d3f0346c6faf5a400b8c5c15f0424f82b0982 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Wed, 2 Oct 2024 16:27:35 +0200 Subject: [PATCH] fix(vitest): make env.SSR consistent between different pools (#6616) --- packages/vitest/src/runtime/runVmTests.ts | 4 ++++ test/core/test/environments/jsdom.spec.ts | 4 ++++ test/core/test/environments/node.spec.ts | 4 ++++ test/core/vitest.workspace.ts | 2 +- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/vitest/src/runtime/runVmTests.ts b/packages/vitest/src/runtime/runVmTests.ts index cee571fbf33d..9d8045c0c5b4 100644 --- a/packages/vitest/src/runtime/runVmTests.ts +++ b/packages/vitest/src/runtime/runVmTests.ts @@ -45,6 +45,10 @@ export async function run( KNOWN_ASSET_TYPES.forEach((type) => { _require.extensions[`.${type}`] = resolveAsset }) + process.env.SSR = '' + } + else { + process.env.SSR = '1' } // @ts-expect-error not typed global for patched timers diff --git a/test/core/test/environments/jsdom.spec.ts b/test/core/test/environments/jsdom.spec.ts index da4d4f43990b..451bd2b9e4f5 100644 --- a/test/core/test/environments/jsdom.spec.ts +++ b/test/core/test/environments/jsdom.spec.ts @@ -101,3 +101,7 @@ test('jsdom global is exposed', () => { dom.reconfigure({ url: 'https://examples.new.com' }) expect(location.href).toBe('https://examples.new.com/') }) + +test('ssr is disabled', () => { + expect(import.meta.env.SSR).toBe(false) +}) diff --git a/test/core/test/environments/node.spec.ts b/test/core/test/environments/node.spec.ts index bae933b50ca2..15e12a30b6f6 100644 --- a/test/core/test/environments/node.spec.ts +++ b/test/core/test/environments/node.spec.ts @@ -9,3 +9,7 @@ test.runIf(nodeMajor > 16)('url correctly creates an object', () => { URL.createObjectURL(new Blob([])) }).not.toThrow() }) + +test('ssr is enabled', () => { + expect(import.meta.env.SSR).toBe(true) +}) diff --git a/test/core/vitest.workspace.ts b/test/core/vitest.workspace.ts index 542aa9bb381a..d58eb7b3cec4 100644 --- a/test/core/vitest.workspace.ts +++ b/test/core/vitest.workspace.ts @@ -1,4 +1,4 @@ -import type { Pool } from 'vitest' +import type { Pool } from 'vitest/node' import { defineWorkspace } from 'vitest/config' function project(pool: Pool) {