mirror of
https://github.com/vitest-dev/vitest.git
synced 2025-12-08 18:26:03 +00:00
43 lines
929 B
TypeScript
43 lines
929 B
TypeScript
import type { Environment } from 'vitest/environments'
|
|
import vm from 'node:vm'
|
|
import { createDebug } from 'obug'
|
|
|
|
// test that external packages (obug) are loaded correctly
|
|
const log = createDebug('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')
|
|
}
|
|
},
|
|
}
|
|
},
|
|
}
|