From 5e3206991ff1b01639d34902a3ad669368a7387e Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Sat, 9 Dec 2023 21:32:46 +0100 Subject: [PATCH 1/2] fix: fix crash when using happy-dom or jsdom on Yarn PnP workspaces --- packages/vitest/src/integrations/env/edge-runtime.ts | 5 ++--- packages/vitest/src/integrations/env/happy-dom.ts | 5 ++--- packages/vitest/src/integrations/env/jsdom.ts | 5 ++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/vitest/src/integrations/env/edge-runtime.ts b/packages/vitest/src/integrations/env/edge-runtime.ts index 875544c08a32..d6a254c9e038 100644 --- a/packages/vitest/src/integrations/env/edge-runtime.ts +++ b/packages/vitest/src/integrations/env/edge-runtime.ts @@ -1,4 +1,3 @@ -import { importModule } from 'local-pkg' import type { Environment } from '../../types' import { populateGlobal } from './utils' import { KEYS } from './jsdom-keys' @@ -7,7 +6,7 @@ export default ({ 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') as typeof import('@edge-runtime/vm') const vm = new EdgeVM({ extend: (context) => { context.global = context @@ -25,7 +24,7 @@ export default ({ } }, async setup(global) { - const { EdgeVM } = await importModule('@edge-runtime/vm') as typeof import('@edge-runtime/vm') + const { EdgeVM } = await import('@edge-runtime/vm') as typeof import('@edge-runtime/vm') const vm = new EdgeVM({ extend: (context) => { context.global = context diff --git a/packages/vitest/src/integrations/env/happy-dom.ts b/packages/vitest/src/integrations/env/happy-dom.ts index 5f0bf594d6a3..dbc1f111b00e 100644 --- a/packages/vitest/src/integrations/env/happy-dom.ts +++ b/packages/vitest/src/integrations/env/happy-dom.ts @@ -1,4 +1,3 @@ -import { importModule } from 'local-pkg' import type { Environment } from '../../types' import { populateGlobal } from './utils' @@ -6,7 +5,7 @@ export default ({ 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') as typeof import('happy-dom') const win = new Window({ ...happyDOM, console: (console && globalThis.console) ? globalThis.console : undefined, @@ -36,7 +35,7 @@ export default ({ 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') as typeof import('happy-dom') const win = new (GlobalWindow || Window)({ ...happyDOM, console: (console && global.console) ? global.console : undefined, diff --git a/packages/vitest/src/integrations/env/jsdom.ts b/packages/vitest/src/integrations/env/jsdom.ts index be93db798cf1..0180bdbb7f59 100644 --- a/packages/vitest/src/integrations/env/jsdom.ts +++ b/packages/vitest/src/integrations/env/jsdom.ts @@ -1,4 +1,3 @@ -import { importModule } from 'local-pkg' import type { Environment } from '../../types' import { populateGlobal } from './utils' @@ -35,7 +34,7 @@ export default ({ JSDOM, ResourceLoader, VirtualConsole, - } = await importModule('jsdom') as typeof import('jsdom') + } = await import('jsdom') as typeof import('jsdom') const { html = '', userAgent, @@ -107,7 +106,7 @@ export default ({ JSDOM, ResourceLoader, VirtualConsole, - } = await importModule('jsdom') as typeof import('jsdom') + } = await import('jsdom') as typeof import('jsdom') const { html = '', userAgent, From 4d79e04d6286ded48524bad8e7d1645ffdd9e1a7 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Thu, 28 Dec 2023 13:30:35 +0100 Subject: [PATCH 2/2] refactor: remove casting --- packages/vitest/src/integrations/env/edge-runtime.ts | 4 ++-- packages/vitest/src/integrations/env/happy-dom.ts | 4 ++-- packages/vitest/src/integrations/env/jsdom.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/vitest/src/integrations/env/edge-runtime.ts b/packages/vitest/src/integrations/env/edge-runtime.ts index d6a254c9e038..84184af41b37 100644 --- a/packages/vitest/src/integrations/env/edge-runtime.ts +++ b/packages/vitest/src/integrations/env/edge-runtime.ts @@ -6,7 +6,7 @@ export default ({ name: 'edge-runtime', transformMode: 'ssr', async setupVM() { - const { EdgeVM } = await import('@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 @@ -24,7 +24,7 @@ export default ({ } }, async setup(global) { - const { EdgeVM } = await import('@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 diff --git a/packages/vitest/src/integrations/env/happy-dom.ts b/packages/vitest/src/integrations/env/happy-dom.ts index dbc1f111b00e..fe7a0d3602da 100644 --- a/packages/vitest/src/integrations/env/happy-dom.ts +++ b/packages/vitest/src/integrations/env/happy-dom.ts @@ -5,7 +5,7 @@ export default ({ name: 'happy-dom', transformMode: 'web', async setupVM({ happyDOM = {} }) { - const { Window } = await import('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, @@ -35,7 +35,7 @@ export default ({ 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 import('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, diff --git a/packages/vitest/src/integrations/env/jsdom.ts b/packages/vitest/src/integrations/env/jsdom.ts index 0180bdbb7f59..ef4937585ed9 100644 --- a/packages/vitest/src/integrations/env/jsdom.ts +++ b/packages/vitest/src/integrations/env/jsdom.ts @@ -34,7 +34,7 @@ export default ({ JSDOM, ResourceLoader, VirtualConsole, - } = await import('jsdom') as typeof import('jsdom') + } = await import('jsdom') const { html = '', userAgent, @@ -106,7 +106,7 @@ export default ({ JSDOM, ResourceLoader, VirtualConsole, - } = await import('jsdom') as typeof import('jsdom') + } = await import('jsdom') const { html = '', userAgent,