From f52840d4cc996deb94fef335b588d0748f15f760 Mon Sep 17 00:00:00 2001 From: Feng Yu Date: Mon, 7 Mar 2022 15:17:42 +0800 Subject: [PATCH] fix(jest-environment-node): Add MessageChannel, MessageEvent to globals (#12553) --- CHANGELOG.md | 1 + packages/jest-environment-node/src/index.ts | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1396884ddbb1..f13f52c65058 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ - `[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/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 e49d7b162c00..bd9718943383 100644 --- a/packages/jest-environment-node/src/index.ts +++ b/packages/jest-environment-node/src/index.ts @@ -78,6 +78,14 @@ export default class NodeEnvironment implements JestEnvironment { if (typeof EventTarget !== 'undefined') { global.EventTarget = EventTarget; } + // MessageChannel is global in Node >= 15 + if (typeof MessageChannel !== 'undefined') { + global.MessageChannel = MessageChannel; + } + // MessageEvent is global in Node >= 15 + if (typeof MessageEvent !== 'undefined') { + global.MessageEvent = MessageEvent; + } // performance is global in Node >= 16 if (typeof performance !== 'undefined') { global.performance = performance;