Skip to content

Commit

Permalink
fix: handle process[toString] being readonly on newer nodes (#8050)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Mar 5, 2019
1 parent 7a4ee21 commit f526a91
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -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

Expand Down
14 changes: 13 additions & 1 deletion packages/jest-util/src/createProcessObject.ts
Expand Up @@ -75,7 +75,19 @@ 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') {
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;
}
}

// Sequentially execute all constructors over the object.
let proto = process;
Expand Down

0 comments on commit f526a91

Please sign in to comment.