Skip to content

Commit

Permalink
fix: remove getVmContext from node env on older versions of node
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Mar 26, 2020
1 parent a679390 commit 47e5ecc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Fixes

- `[jest-environment-node]` Remove `getVmContext` from Node env on older versions of Node ([#9706](https://github.com/facebook/jest/pull/9706))

### Chore & Maintenance

### Performance
Expand Down
6 changes: 5 additions & 1 deletion packages/jest-environment-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
"@jest/fake-timers": "^25.2.1",
"@jest/types": "^25.2.1",
"jest-mock": "^25.2.1",
"jest-util": "^25.2.1"
"jest-util": "^25.2.1",
"semver": "^6.3.0"
},
"devDependencies": {
"@types/semver": "^6.2.0"
},
"engines": {
"node": ">= 8.3"
Expand Down
8 changes: 8 additions & 0 deletions packages/jest-environment-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
LolexFakeTimers,
} from '@jest/fake-timers';
import type {JestEnvironment} from '@jest/environment';
import {lt as semverLt} from 'semver';

type Timer = {
id: number;
Expand Down Expand Up @@ -121,4 +122,11 @@ class NodeEnvironment implements JestEnvironment {
}
}

// node 10 had a bug in `vm.compileFunction` that was fixed in https://github.com/nodejs/node/pull/23206.
// Let's just pretend the env doesn't support the function.
// Make sure engine requirement is high enough when we drop node 8 so we can remove this condition
if (semverLt(process.version, '10.14.2')) {
delete NodeEnvironment.prototype.getVmContext;
}

export = NodeEnvironment;
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2489,7 +2489,7 @@
dependencies:
"@types/node" "*"

"@types/semver@^6.0.1", "@types/semver@^6.2.1":
"@types/semver@^6.0.1", "@types/semver@^6.2.0", "@types/semver@^6.2.1":
version "6.2.1"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-6.2.1.tgz#a236185670a7860f1597cf73bea2e16d001461ba"
integrity sha512-+beqKQOh9PYxuHvijhVl+tIHvT6tuwOrE9m14zd+MT2A38KoKZhh7pYJ0SNleLtwDsiIxHDsIk9bv01oOxvSvA==
Expand Down

0 comments on commit 47e5ecc

Please sign in to comment.