Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/environments/vitest/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Environment } from 'vitest/environments'
import { resolveModulePath } from 'exsolve'
import { indexedDB } from 'fake-indexeddb'
import { joinURL } from 'ufo'
import defu from 'defu'
import { populateGlobal } from 'vitest/environments'

import { setupWindow } from '../../runtime/shared/environment'
import type { NuxtBuiltinEnvironment } from './types'
Expand All @@ -18,6 +18,8 @@ export default <Environment>{
name: 'nuxt',
viteEnvironment: 'client',
async setup(global, environmentOptions) {
const { populateGlobal } = await importVitestEnvironments()

const url = joinURL(
environmentOptions.nuxt?.url ?? 'http://localhost:3000',
environmentOptions.nuxtRuntimeConfig?.app?.baseURL || '/',
Expand Down Expand Up @@ -65,6 +67,12 @@ export default <Environment>{
},
}

// This can be removed when dropping support for vitest 4.0.x (We can static import from 'vitest/runtime')
async function importVitestEnvironments() {
const pkg = resolveModulePath('vitest/runtime', { try: true }) ? 'vitest/runtime' : 'vitest/environments'
return await import(pkg) as typeof import('vitest/environments')
}

class IntersectionObserver {
observe() {}
unobserve() {}
Expand Down
Loading