vitest/test/cli/custom.ts
Vladimir 9be01ba594
feat!: use module-runner instead of vite-node (#8208)
Co-authored-by: Ari Perkkiö <ari.perkkio@gmail.com>
2025-07-28 13:43:53 +02:00

43 lines
915 B
TypeScript

import type { Environment } from 'vitest/environments'
import vm from 'node:vm'
import debug from 'debug'
// test that external packages (debug) are loaded correctly
const log = debug('test:env')
export default <Environment>{
name: 'custom',
viteEnvironment: 'ssr',
setupVM({ custom }) {
const context = vm.createContext({
testEnvironment: 'custom',
option: custom.option,
setTimeout,
clearTimeout,
})
return {
getVmContext() {
return context
},
teardown() {
delete context.testEnvironment
delete context.option
},
}
},
setup(global, { custom }) {
global.testEnvironment = 'custom'
global.option = custom.option
return {
teardown() {
delete global.testEnvironment
delete global.option
if (global.__exists) {
log('should not log')
}
},
}
},
}