From 11783816bac354ea547bbab063638d5053b9a07d Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 5 Mar 2019 11:10:34 +0100 Subject: [PATCH 1/4] fix: handle process[toString] being readonly on enwer nodes --- packages/jest-util/src/createProcessObject.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/jest-util/src/createProcessObject.ts b/packages/jest-util/src/createProcessObject.ts index f6d5b65843a8..3b2d60a1c418 100644 --- a/packages/jest-util/src/createProcessObject.ts +++ b/packages/jest-util/src/createProcessObject.ts @@ -75,7 +75,17 @@ export default function() { keepPrototype: true, }); - newProcess[Symbol.toStringTag] = 'process'; + try { + // This fails on Node 12, but it's already set to 'process' + newProcess[Symbol.toStringTag] = 'process'; + } catch (e) { + // Make sure it's actually set instead of potentially ignoring errors + if (newProcess[Symbol.toStringTag] !== 'process') { + throw new Error( + 'Unable to set toStringTag on process. Please open up an issue at https://github.com/facebook/jest', + ); + } + } // Sequentially execute all constructors over the object. let proto = process; From f206347beeef818ab06405935883d6b6a3092905 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 5 Mar 2019 11:13:52 +0100 Subject: [PATCH 2/4] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39d765fd161b..32e7c928e9b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ - `[jest-circus]`: Throw explicit error when errors happen after test is considered complete ([#8005](https://github.com/facebook/jest/pull/8005)) - `[expect]` Remove duck typing and obsolete browser support code when comparing DOM nodes and use DOM-Level-3 API instead ([#7995](https://github.com/facebook/jest/pull/7995)) - `[jest-mock]` Adds a type check to `prototype` to allow mocks of objects with a primitive `prototype` property. ([#8040](https://github.com/facebook/jest/pull/8040)) +- `[jest-util]`Make sure to not fail if unable to assign `toStringTag` to the `process` object, which is read only in Node 12 ([#8050](https://github.com/facebook/jest/pull/8050)) ### Chore & Maintenance From 6d0ce2314a30c8e9998db66ca5e7bfa7b601afe1 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 5 Mar 2019 11:14:13 +0100 Subject: [PATCH 3/4] fix typos in changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32e7c928e9b5..dd0bfd0fb82d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ ### Fixes -- `[jest-environment-node]` Add mising globals: TextEncoder and TextDecoder ([#8022](https://github.com/facebook/jest/pull/8022)) +- `[jest-environment-node]` Add missing globals: TextEncoder and TextDecoder ([#8022](https://github.com/facebook/jest/pull/8022)) - `[jest-cli]` Fix prototype pollution vulnerability in dependency ([#7904](https://github.com/facebook/jest/pull/7904)) - `[jest-cli]` Refactor `-o` and `--coverage` combined ([#7611](https://github.com/facebook/jest/pull/7611)) - `[expect]` Fix custom async matcher stack trace ([#7652](https://github.com/facebook/jest/pull/7652)) @@ -24,7 +24,7 @@ - `[jest-changed-files]` Improve default file selection for Mercurial repos ([#7880](https://github.com/facebook/jest/pull/7880)) - `[jest-validate]` Fix validating async functions ([#7894](https://github.com/facebook/jest/issues/7894)) - `[jest-circus]` Fix bug with test.only ([#7888](https://github.com/facebook/jest/pull/7888)) -- `[jest-transform]` Normalize config and remove unecessary checks, convert `TestUtils.js` to TypeScript ([#7801](https://github.com/facebook/jest/pull/7801)) +- `[jest-transform]` Normalize config and remove unnecessary checks, convert `TestUtils.js` to TypeScript ([#7801](https://github.com/facebook/jest/pull/7801)) - `[jest-worker]` Fix `jest-worker` when using pre-allocated jobs ([#7934](https://github.com/facebook/jest/pull/7934)) - `[jest-changed-files]` Fix `getChangedFilesFromRoots` to not return parts of the commit messages as if they were files, when the commit messages contained multiple paragraphs ([#7961](https://github.com/facebook/jest/pull/7961)) - `[jest-haste-map]` Enforce uniqueness in names (mocks and haste ids) ([#8002](https://github.com/facebook/jest/pull/8002)) From a5e4910f62a11b2a26db91f87688174ae0f2bb9b Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 5 Mar 2019 11:16:11 +0100 Subject: [PATCH 4/4] do not remove original error, only add to its message --- packages/jest-util/src/createProcessObject.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/jest-util/src/createProcessObject.ts b/packages/jest-util/src/createProcessObject.ts index 3b2d60a1c418..903336636bdd 100644 --- a/packages/jest-util/src/createProcessObject.ts +++ b/packages/jest-util/src/createProcessObject.ts @@ -81,9 +81,11 @@ export default function() { } catch (e) { // Make sure it's actually set instead of potentially ignoring errors if (newProcess[Symbol.toStringTag] !== 'process') { - throw new Error( - 'Unable to set toStringTag on process. Please open up an issue at https://github.com/facebook/jest', - ); + e.message = + 'Unable to set toStringTag on process. Please open up an issue at https://github.com/facebook/jest\n\n' + + e.message; + + throw e; } }