From 60f8f49f7eea6e3cc37f2492eb4e441170f5fe81 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 27 Jan 2022 17:02:00 +0100 Subject: [PATCH 1/4] jest-environment-node: add `atob` and `btoa` Fixes: https://github.com/facebook/jest/issues/12268 --- packages/jest-environment-node/src/index.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/jest-environment-node/src/index.ts b/packages/jest-environment-node/src/index.ts index 385821e810d4..ab9bf445da7c 100644 --- a/packages/jest-environment-node/src/index.ts +++ b/packages/jest-environment-node/src/index.ts @@ -82,6 +82,13 @@ class NodeEnvironment implements JestEnvironment { if (typeof performance !== 'undefined') { global.performance = performance; } + if ( + typeof atob !== 'undefined' && + typeof btoa !== 'undefined' + ) { + global.atob = atob; + global.btoa = btoa; + } installCommonGlobals(global, config.globals); this.moduleMocker = new ModuleMocker(global); From 920b844218cb8326d78a9db85c1fe341a3598ee1 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 27 Jan 2022 18:16:35 +0100 Subject: [PATCH 2/4] add comment --- packages/jest-environment-node/src/index.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/jest-environment-node/src/index.ts b/packages/jest-environment-node/src/index.ts index ab9bf445da7c..5c180b2ca1b1 100644 --- a/packages/jest-environment-node/src/index.ts +++ b/packages/jest-environment-node/src/index.ts @@ -82,10 +82,8 @@ class NodeEnvironment implements JestEnvironment { if (typeof performance !== 'undefined') { global.performance = performance; } - if ( - typeof atob !== 'undefined' && - typeof btoa !== 'undefined' - ) { + // performance is global in Node >= 16 + if (typeof atob !== 'undefined' && typeof btoa !== 'undefined') { global.atob = atob; global.btoa = btoa; } From c2056f3f70f2a5bdca0b8064e1bb79bf75c831ce Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 27 Jan 2022 18:19:17 +0100 Subject: [PATCH 3/4] fixup! add comment --- packages/jest-environment-node/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-environment-node/src/index.ts b/packages/jest-environment-node/src/index.ts index 5c180b2ca1b1..27b65b5add37 100644 --- a/packages/jest-environment-node/src/index.ts +++ b/packages/jest-environment-node/src/index.ts @@ -82,7 +82,7 @@ class NodeEnvironment implements JestEnvironment { if (typeof performance !== 'undefined') { global.performance = performance; } - // performance is global in Node >= 16 + // atob and btoa are global in Node >= 16 if (typeof atob !== 'undefined' && typeof btoa !== 'undefined') { global.atob = atob; global.btoa = btoa; From 55c9a7587f0145e25658ec81cbfc1a9596da2e7e Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 28 Jan 2022 07:51:49 +0100 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cdded6df47d..09a785d68a7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Fixes +- `[jest-environment-node]` Add `atob` and `btoa` ([#12269](https://github.com/facebook/jest/pull/12269)) + ### Chore & Maintenance - `[*]` Update graceful-fs to ^4.2.9 ([#11749](https://github.com/facebook/jest/pull/11749))