Skip to content

Commit

Permalink
fix(vitest): make env.SSR consistent between different pools (#6616)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored Oct 2, 2024
1 parent ed8b7c0 commit 8a8d3f0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/vitest/src/runtime/runVmTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/core/test/environments/jsdom.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
4 changes: 4 additions & 0 deletions test/core/test/environments/node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
2 changes: 1 addition & 1 deletion test/core/vitest.workspace.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Pool } from 'vitest'
import type { Pool } from 'vitest/node'
import { defineWorkspace } from 'vitest/config'

function project(pool: Pool) {
Expand Down

0 comments on commit 8a8d3f0

Please sign in to comment.