From b4c775438afe3369280b6b0985e4250fa8fae414 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Mon, 4 Apr 2022 19:40:29 +0300 Subject: [PATCH 1/3] fix(jest-environment-node): Add structuredClone to globals --- CHANGELOG.md | 1 + packages/jest-environment-node/src/index.ts | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4f92643ebbd..7ad8f38d8da9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ - `[jest-environment-jsdom]` Make `jsdom` accessible to extending environments again ([#12232](https://github.com/facebook/jest/pull/12232)) - `[jest-environment-jsdom]` Log JSDOM errors more cleanly ([#12386](https://github.com/facebook/jest/pull/12386)) - `[jest-environment-node]` Add MessageChannel, MessageEvent to globals ([#12553](https://github.com/facebook/jest/pull/12553)) +- `[jest-environment-node]` Add structuredClone to globals ([#12631](https://github.com/facebook/jest/pull/12631)) - `[@jest/expect-utils]` [**BREAKING**] Fix false positives when looking for `undefined` prop ([#8923](https://github.com/facebook/jest/pull/8923)) - `[jest-haste-map]` Don't use partial results if file crawl errors ([#12420](https://github.com/facebook/jest/pull/12420)) - `[jest-jasmine2, jest-types]` [**BREAKING**] Move all `jasmine` specific types from `@jest/types` to its own package ([#12125](https://github.com/facebook/jest/pull/12125)) diff --git a/packages/jest-environment-node/src/index.ts b/packages/jest-environment-node/src/index.ts index bd9718943383..8abee4e5e0c1 100644 --- a/packages/jest-environment-node/src/index.ts +++ b/packages/jest-environment-node/src/index.ts @@ -95,6 +95,10 @@ export default class NodeEnvironment implements JestEnvironment { global.atob = atob; global.btoa = btoa; } + // structuredClone is global in Node >= 17 + if (typeof structuredClone !== 'undefined') { + global.structuredClone = structuredClone; + } installCommonGlobals(global, projectConfig.globals); this.moduleMocker = new ModuleMocker(global); From 2736645795a41b11405973c80b08b444937ca558 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 4 Apr 2022 20:08:32 +0200 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ad8f38d8da9..af484a94a4f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,8 +59,8 @@ - `[jest-each]` `%#` is not replaced with index of the test case ([#12517](https://github.com/facebook/jest/pull/12517)) - `[jest-environment-jsdom]` Make `jsdom` accessible to extending environments again ([#12232](https://github.com/facebook/jest/pull/12232)) - `[jest-environment-jsdom]` Log JSDOM errors more cleanly ([#12386](https://github.com/facebook/jest/pull/12386)) -- `[jest-environment-node]` Add MessageChannel, MessageEvent to globals ([#12553](https://github.com/facebook/jest/pull/12553)) -- `[jest-environment-node]` Add structuredClone to globals ([#12631](https://github.com/facebook/jest/pull/12631)) +- `[jest-environment-node]` Add `MessageChannel`, `MessageEvent` to globals ([#12553](https://github.com/facebook/jest/pull/12553)) +- `[jest-environment-node]` Add `structuredClone` to globals ([#12631](https://github.com/facebook/jest/pull/12631)) - `[@jest/expect-utils]` [**BREAKING**] Fix false positives when looking for `undefined` prop ([#8923](https://github.com/facebook/jest/pull/8923)) - `[jest-haste-map]` Don't use partial results if file crawl errors ([#12420](https://github.com/facebook/jest/pull/12420)) - `[jest-jasmine2, jest-types]` [**BREAKING**] Move all `jasmine` specific types from `@jest/types` to its own package ([#12125](https://github.com/facebook/jest/pull/12125)) From 41d8c4aa381f3ce03b91a867e0535b5aac0dee29 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Mon, 4 Apr 2022 21:43:44 +0300 Subject: [PATCH 3/3] fix(jest-environment-node): expect missing structuredClone type definition --- packages/jest-environment-node/src/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/jest-environment-node/src/index.ts b/packages/jest-environment-node/src/index.ts index 8abee4e5e0c1..f6f8576bd6e6 100644 --- a/packages/jest-environment-node/src/index.ts +++ b/packages/jest-environment-node/src/index.ts @@ -96,7 +96,9 @@ export default class NodeEnvironment implements JestEnvironment { global.btoa = btoa; } // structuredClone is global in Node >= 17 + // @ts-expect-error type definition for structuredClone is missing if (typeof structuredClone !== 'undefined') { + // @ts-expect-error type definition for structuredClone is missing global.structuredClone = structuredClone; } installCommonGlobals(global, projectConfig.globals);