Skip to content

Commit ee8b46d

Browse files
wojtekmajsheremet-va
andauthoredDec 28, 2023
fix: don't crash when using happy-dom or jsdom environment on Yarn PnP workspaces (#4698)
Co-authored-by: Vladimir Sheremet <sleuths.slews0s@icloud.com>
1 parent a3719fa commit ee8b46d

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed
 

‎packages/vitest/src/integrations/env/edge-runtime.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { importModule } from 'local-pkg'
21
import type { Environment } from '../../types'
32
import { populateGlobal } from './utils'
43
import { KEYS } from './jsdom-keys'
@@ -7,7 +6,7 @@ export default <Environment>({
76
name: 'edge-runtime',
87
transformMode: 'ssr',
98
async setupVM() {
10-
const { EdgeVM } = await importModule('@edge-runtime/vm') as typeof import('@edge-runtime/vm')
9+
const { EdgeVM } = await import('@edge-runtime/vm')
1110
const vm = new EdgeVM({
1211
extend: (context) => {
1312
context.global = context
@@ -25,7 +24,7 @@ export default <Environment>({
2524
}
2625
},
2726
async setup(global) {
28-
const { EdgeVM } = await importModule('@edge-runtime/vm') as typeof import('@edge-runtime/vm')
27+
const { EdgeVM } = await import('@edge-runtime/vm')
2928
const vm = new EdgeVM({
3029
extend: (context) => {
3130
context.global = context

‎packages/vitest/src/integrations/env/happy-dom.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { importModule } from 'local-pkg'
21
import type { Environment } from '../../types'
32
import { populateGlobal } from './utils'
43

54
export default <Environment>({
65
name: 'happy-dom',
76
transformMode: 'web',
87
async setupVM({ happyDOM = {} }) {
9-
const { Window } = await importModule('happy-dom') as typeof import('happy-dom')
8+
const { Window } = await import('happy-dom')
109
const win = new Window({
1110
...happyDOM,
1211
console: (console && globalThis.console) ? globalThis.console : undefined,
@@ -36,7 +35,7 @@ export default <Environment>({
3635
async setup(global, { happyDOM = {} }) {
3736
// happy-dom v3 introduced a breaking change to Window, but
3837
// provides GlobalWindow as a way to use previous behaviour
39-
const { Window, GlobalWindow } = await importModule('happy-dom') as typeof import('happy-dom')
38+
const { Window, GlobalWindow } = await import('happy-dom')
4039
const win = new (GlobalWindow || Window)({
4140
...happyDOM,
4241
console: (console && global.console) ? global.console : undefined,

‎packages/vitest/src/integrations/env/jsdom.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { importModule } from 'local-pkg'
21
import type { Environment } from '../../types'
32
import { populateGlobal } from './utils'
43

@@ -35,7 +34,7 @@ export default <Environment>({
3534
JSDOM,
3635
ResourceLoader,
3736
VirtualConsole,
38-
} = await importModule('jsdom') as typeof import('jsdom')
37+
} = await import('jsdom')
3938
const {
4039
html = '<!DOCTYPE html>',
4140
userAgent,
@@ -107,7 +106,7 @@ export default <Environment>({
107106
JSDOM,
108107
ResourceLoader,
109108
VirtualConsole,
110-
} = await importModule('jsdom') as typeof import('jsdom')
109+
} = await import('jsdom')
111110
const {
112111
html = '<!DOCTYPE html>',
113112
userAgent,

0 commit comments

Comments
 (0)
Please sign in to comment.