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 acfbd7f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
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
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
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 acfbd7f

Please sign in to comment.