Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix crash when using happy-dom or jsdom environment on Yarn PnP workspaces #4698

Merged
merged 2 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading