From ae2c56178456c1e99af879d3d2a5fd644c3b65d0 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 5 May 2022 19:54:48 +0300 Subject: [PATCH] fix: happy-dom v3 crashes (#1234) --- bench/package.json | 2 +- package.json | 1 - packages/vitest/package.json | 2 +- .../vitest/src/integrations/env/happy-dom.ts | 6 ++++-- pnpm-lock.yaml | 21 +++++++++---------- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/bench/package.json b/bench/package.json index 3c393ded9325..b83380fd25bd 100644 --- a/bench/package.json +++ b/bench/package.json @@ -9,7 +9,7 @@ "@actions/core": "^1.7.0", "@actions/exec": "^1.1.1", "@actions/github": "^5.0.1", - "@happy-dom/jest-environment": "^2.55.0", + "@happy-dom/jest-environment": "^3.1.1", "@types/benchmark": "^2.1.1", "benchmark": "^2.1.4", "esmo": "^0.14.1", diff --git a/package.json b/package.json index 69c048849d2f..3434bafee469 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,6 @@ "pnpm": { "overrides": { "vite": "^2.9.5", - "happy-dom": "^2.55.0", "vitest": "workspace:*" } }, diff --git a/packages/vitest/package.json b/packages/vitest/package.json index d24754c06146..fb8378710685 100644 --- a/packages/vitest/package.json +++ b/packages/vitest/package.json @@ -109,7 +109,7 @@ "fast-glob": "^3.2.11", "find-up": "^6.3.0", "flatted": "^3.2.5", - "happy-dom": "^2.55.0", + "happy-dom": "^3.1.1", "jsdom": "^19.0.0", "log-update": "^5.0.1", "magic-string": "^0.26.1", diff --git a/packages/vitest/src/integrations/env/happy-dom.ts b/packages/vitest/src/integrations/env/happy-dom.ts index 35d3ddc2e68e..8817d0b5b908 100644 --- a/packages/vitest/src/integrations/env/happy-dom.ts +++ b/packages/vitest/src/integrations/env/happy-dom.ts @@ -5,8 +5,10 @@ import { getWindowKeys } from './utils' export default ({ name: 'happy-dom', async setup(global) { - const { Window } = await importModule('happy-dom') as typeof import('happy-dom') - const win: any = new Window() + // 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: any = new (GlobalWindow || Window)() const keys = getWindowKeys(global, win) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index df4000af42e4..f662e7e67ee7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2,7 +2,6 @@ lockfileVersion: 5.4 overrides: vite: ^2.9.5 - happy-dom: ^2.55.0 vitest: workspace:* importers: @@ -144,7 +143,7 @@ importers: examples/lit: specifiers: '@vitest/ui': latest - happy-dom: ^2.55.0 + happy-dom: latest lit: ^2.2.3 vite: ^2.9.5 vitest: workspace:* @@ -152,7 +151,7 @@ importers: lit: 2.2.3 devDependencies: '@vitest/ui': link:../../packages/ui - happy-dom: 2.55.0 + happy-dom: 3.1.1 vite: 2.9.5 vitest: link:../../packages/vitest @@ -216,7 +215,7 @@ importers: '@types/react-test-renderer': ^17.0.2 '@vitejs/plugin-react': 1.3.1 '@vitest/ui': latest - happy-dom: ^2.55.0 + happy-dom: latest jsdom: latest react: ^17.0.2 react-test-renderer: 17.0.2 @@ -228,7 +227,7 @@ importers: '@types/react-test-renderer': 17.0.2 '@vitejs/plugin-react': 1.3.1 '@vitest/ui': link:../../packages/ui - happy-dom: 2.55.0 + happy-dom: 3.1.1 jsdom: 19.0.0 react-test-renderer: 17.0.2_react@17.0.2 vitest: link:../../packages/vitest @@ -471,7 +470,7 @@ importers: specifiers: '@vitejs/plugin-vue': ^2.3.1 '@vue/test-utils': ^2.0.0-rc.21 - happy-dom: ^2.55.0 + happy-dom: latest unplugin-auto-import: ^0.7.1 unplugin-vue-components: ^0.19.3 vitest: workspace:* @@ -481,7 +480,7 @@ importers: devDependencies: '@vitejs/plugin-vue': 2.3.1_vue@3.2.33 '@vue/test-utils': 2.0.0-rc.21_vue@3.2.33 - happy-dom: 2.55.0 + happy-dom: 3.1.1 unplugin-auto-import: 0.7.1 unplugin-vue-components: 0.19.3_vue@3.2.33 vitest: link:../../packages/vitest @@ -634,7 +633,7 @@ importers: fast-glob: ^3.2.11 find-up: ^6.3.0 flatted: ^3.2.5 - happy-dom: ^2.55.0 + happy-dom: ^3.1.1 jsdom: ^19.0.0 local-pkg: ^0.4.1 log-update: ^5.0.1 @@ -685,7 +684,7 @@ importers: fast-glob: 3.2.11 find-up: 6.3.0 flatted: 3.2.5 - happy-dom: 2.55.0 + happy-dom: 3.1.1 jsdom: 19.0.0 log-update: 5.0.1 magic-string: 0.26.1 @@ -12153,8 +12152,8 @@ packages: uglify-js: 3.15.4 dev: true - /happy-dom/2.55.0: - resolution: {integrity: sha512-CHDMBRau+l/yKQL+ANmexRAC8FRCuYbXRSpu/GbLVyfqkrlBzV7OSNd5C5HZ+pVFtFv1bFJYC5r+xrqgGQuq5w==} + /happy-dom/3.1.1: + resolution: {integrity: sha512-yomqZv0JJ3FSQ/OZXiDSNOqw/vxZEzrFpxXausyyGPMICZs3KIGfQt+X/007abXkQWRb1SDeetM4PqOM0cagfQ==} dependencies: css.escape: 1.5.1 he: 1.2.0