diff --git a/packages/vitest/src/integrations/env/happy-dom.ts b/packages/vitest/src/integrations/env/happy-dom.ts index 3df3b2bd3b5b..dc63e818aabf 100644 --- a/packages/vitest/src/integrations/env/happy-dom.ts +++ b/packages/vitest/src/integrations/env/happy-dom.ts @@ -2,11 +2,13 @@ import { importModule } from 'local-pkg' import type { Environment } from '../../types' import { populateGlobal } from './utils' -export default ({ +export default { name: 'happy-dom', transformMode: 'web', async setupVM() { - const { Window } = await importModule('happy-dom') as typeof import('happy-dom') + const { Window } = (await importModule( + 'happy-dom', + )) as typeof import('happy-dom') const win = new Window() as any // TODO: browser doesn't expose Buffer, but a lot of dependencies use it @@ -29,17 +31,21 @@ export default ({ 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 { Window, GlobalWindow } = (await importModule( + 'happy-dom', + )) as typeof import('happy-dom') + const win = new (GlobalWindow || Window)({ url: 'http://localhost:3000' }) - const { keys, originals } = populateGlobal(global, win, { bindFunctions: true }) + 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) + originals.forEach((v, k) => (global[k] = v)) }, } }, -}) +}