From 69bb4132b0c6a84976f80144b3e87e47de635507 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Mon, 6 Jun 2022 17:26:41 +0300 Subject: [PATCH 1/2] fix: allow accessing Audio, Option on global --- packages/vitest/src/integrations/env/jsdom-keys.ts | 2 ++ test/core/test/dom.test.ts | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/vitest/src/integrations/env/jsdom-keys.ts b/packages/vitest/src/integrations/env/jsdom-keys.ts index ea77801552d8..c349f95c1c95 100644 --- a/packages/vitest/src/integrations/env/jsdom-keys.ts +++ b/packages/vitest/src/integrations/env/jsdom-keys.ts @@ -162,6 +162,8 @@ const LIVING_KEYS = [ // not specified in docs, but is available 'Image', + 'Audio', + 'Option', ] const OTHER_KEYS = [ diff --git a/test/core/test/dom.test.ts b/test/core/test/dom.test.ts index 1be843461d7a..1756a5065fe4 100644 --- a/test/core/test/dom.test.ts +++ b/test/core/test/dom.test.ts @@ -27,10 +27,14 @@ it('dispatchEvent doesn\'t throw', () => { expect(() => target.dispatchEvent(event)).not.toThrow() }) -it('Image works as expected', () => { +it('Non-public "live" keys work as expected', () => { const img = new Image(100) + const audio = new Audio() + const option = new Option() expect(img.width).toBe(100) + expect(audio).toBeInstanceOf(window.Audio) + expect(option).toBeInstanceOf(window.Option) }) it('defined on self/window are defined on global', () => { From 30f0ded1dfc82e1c0cccd6826a9b455d6eec9ca4 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Wed, 8 Jun 2022 20:49:27 +0300 Subject: [PATCH 2/2] chore: allow private jsdom properties on globalThis --- packages/vitest/src/integrations/env/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vitest/src/integrations/env/utils.ts b/packages/vitest/src/integrations/env/utils.ts index 074cd9bb5adf..c412ebcef09b 100644 --- a/packages/vitest/src/integrations/env/utils.ts +++ b/packages/vitest/src/integrations/env/utils.ts @@ -15,7 +15,7 @@ const skipKeys = [ export function getWindowKeys(global: any, win: any) { const keys = new Set(KEYS.concat(Object.getOwnPropertyNames(win)) .filter((k) => { - if (k.startsWith('_') || skipKeys.includes(k)) + if (skipKeys.includes(k)) return false if (k in global) return allowRewrite.includes(k)