forked from vitest-dev/vitest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
happy-dom.ts
24 lines (21 loc) · 786 Bytes
/
happy-dom.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { importModule } from 'local-pkg'
import type { Environment } from '../../types'
import { populateGlobal } from './utils'
export default <Environment>({
name: 'happy-dom',
transformMode: 'web',
async setup(global) {
// happy-dom v3 introduced a breaking change to Window, but
// provides GlobalWindow as a way to use previous behaviour
const { Window, GlobalWindow } = await importModule('happy-dom') as typeof import('happy-dom')
const win = new (GlobalWindow || Window)()
const { keys, originals } = populateGlobal(global, win, { bindFunctions: true })
return {
teardown(global) {
win.happyDOM.cancelAsync()
keys.forEach(key => delete global[key])
originals.forEach((v, k) => global[k] = v)
},
}
},
})