Skip to content

Commit

Permalink
fix: don't crash when using happy-dom or jsdom environment on Yarn Pn…
Browse files Browse the repository at this point in the history
…P workspaces (#4698)

Co-authored-by: Vladimir Sheremet <[email protected]>
  • Loading branch information
wojtekmaj and sheremet-va committed Dec 28, 2023
1 parent a3719fa commit ee8b46d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
5 changes: 2 additions & 3 deletions packages/vitest/src/integrations/env/edge-runtime.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { importModule } from 'local-pkg'
import type { Environment } from '../../types'
import { populateGlobal } from './utils'
import { KEYS } from './jsdom-keys'
Expand All @@ -7,7 +6,7 @@ export default <Environment>({
name: 'edge-runtime',
transformMode: 'ssr',
async setupVM() {
const { EdgeVM } = await importModule('@edge-runtime/vm') as typeof import('@edge-runtime/vm')
const { EdgeVM } = await import('@edge-runtime/vm')
const vm = new EdgeVM({
extend: (context) => {
context.global = context
Expand All @@ -25,7 +24,7 @@ export default <Environment>({
}
},
async setup(global) {
const { EdgeVM } = await importModule('@edge-runtime/vm') as typeof import('@edge-runtime/vm')
const { EdgeVM } = await import('@edge-runtime/vm')
const vm = new EdgeVM({
extend: (context) => {
context.global = context
Expand Down
5 changes: 2 additions & 3 deletions packages/vitest/src/integrations/env/happy-dom.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { importModule } from 'local-pkg'
import type { Environment } from '../../types'
import { populateGlobal } from './utils'

export default <Environment>({
name: 'happy-dom',
transformMode: 'web',
async setupVM({ happyDOM = {} }) {
const { Window } = await importModule('happy-dom') as typeof import('happy-dom')
const { Window } = await import('happy-dom')
const win = new Window({
...happyDOM,
console: (console && globalThis.console) ? globalThis.console : undefined,
Expand Down Expand Up @@ -36,7 +35,7 @@ export default <Environment>({
async setup(global, { happyDOM = {} }) {
// 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 { Window, GlobalWindow } = await import('happy-dom')
const win = new (GlobalWindow || Window)({
...happyDOM,
console: (console && global.console) ? global.console : undefined,
Expand Down
5 changes: 2 additions & 3 deletions packages/vitest/src/integrations/env/jsdom.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { importModule } from 'local-pkg'
import type { Environment } from '../../types'
import { populateGlobal } from './utils'

Expand Down Expand Up @@ -35,7 +34,7 @@ export default <Environment>({
JSDOM,
ResourceLoader,
VirtualConsole,
} = await importModule('jsdom') as typeof import('jsdom')
} = await import('jsdom')
const {
html = '<!DOCTYPE html>',
userAgent,
Expand Down Expand Up @@ -107,7 +106,7 @@ export default <Environment>({
JSDOM,
ResourceLoader,
VirtualConsole,
} = await importModule('jsdom') as typeof import('jsdom')
} = await import('jsdom')
const {
html = '<!DOCTYPE html>',
userAgent,
Expand Down

0 comments on commit ee8b46d

Please sign in to comment.