Skip to content

Commit

Permalink
fix: remove getVmContext from node env on older versions of n… (#9708)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Mar 26, 2020
1 parent a679390 commit d1c81fd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
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.1"
},
"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;

0 comments on commit d1c81fd

Please sign in to comment.