From c7b15385a67c4380af9eea83638f8203b8472225 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Mon, 4 Apr 2022 22:07:47 +0300 Subject: [PATCH] fix(jest-environment-node): Add `structuredClone` to globals (#12631) --- CHANGELOG.md | 3 ++- packages/jest-environment-node/src/index.ts | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4f92643ebbd..af484a94a4f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,7 +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 `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..f6f8576bd6e6 100644 --- a/packages/jest-environment-node/src/index.ts +++ b/packages/jest-environment-node/src/index.ts @@ -95,6 +95,12 @@ export default class NodeEnvironment implements JestEnvironment { global.atob = atob; 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); this.moduleMocker = new ModuleMocker(global);