Specific Files
ts
// @vitest-environment jsdom
import { expect, test } from 'vitest'
test('test', () => {
expect(typeof window).not.toBe('undefined')
})
Custom Environment
ts
import type { Environment } from 'vitest'
export default <Environment>{
name: 'custom',
transformMode: 'ssr',
// optional - only if you support "experimental-vm" pool
async setupVM() {
const vm = await import('node:vm')
const context = vm.createContext()
return {
getVmContext() {
return context
},
teardown() {
// called after all tests with this env have been run
}
}
},
setup() {
// custom setup
return {
teardown() {
// called after all tests with this env have been run
}
}
}
}