Skip to content

Commit 130bb18

Browse files
committed
chore: replace vm.Script with vm.compileFunction
Memory leak is alleviated with `vm.compileFunction`. However, implementing `importModuleDynamically` causes memory to leak again, so that has been skipped. Fixes #11956
1 parent 0f99ff5 commit 130bb18

File tree

12 files changed

+41
-110
lines changed

12 files changed

+41
-110
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
### Performance
1010

11+
- `[jest-runtime]` Replace `vm.Script` with `vm.compileFunction` to address memory leak ([#12205](https://github.com/facebook/jest/pull/12205))
12+
1113
## 27.4.6
1214

1315
### Fixes

e2e/__tests__/__snapshots__/consoleLogOutputWhenRunInBand.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ exports[`prints console.logs when run with forceExit 3`] = `
2020
console.log
2121
Hey
2222
23-
at Object.<anonymous> (__tests__/a-banana.js:1:1)
23+
at Object.log (__tests__/a-banana.js:1:30)
2424
2525
`;

e2e/__tests__/__snapshots__/coverageProviderV8.test.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ exports[`prints correct coverage report, if a CJS module is put under test witho
4040
--------------|---------|----------|---------|---------|-------------------
4141
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
4242
--------------|---------|----------|---------|---------|-------------------
43-
All files | 59.37 | 60 | 50 | 59.37 |
44-
module.js | 79.16 | 75 | 66.66 | 79.16 | 14-16,19-20
43+
All files | 56.25 | 50 | 33.33 | 56.25 |
44+
module.js | 75 | 66.66 | 50 | 75 | 7-10,12-13
4545
uncovered.js | 0 | 0 | 0 | 0 | 1-8
4646
--------------|---------|----------|---------|---------|-------------------
4747
`;
@@ -55,8 +55,8 @@ exports[`prints correct coverage report, if a TS module is transpiled by Babel t
5555
--------------|---------|----------|---------|---------|-------------------
5656
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
5757
--------------|---------|----------|---------|---------|-------------------
58-
All files | 50 | 25 | 25 | 50 |
59-
module.ts | 80.76 | 50 | 50 | 80.76 | 16-18,21-22
58+
All files | 59.52 | 25 | 33.33 | 59.52 |
59+
module.ts | 96.15 | 50 | 100 | 96.15 | 15
6060
types.ts | 0 | 0 | 0 | 0 | 1-8
6161
uncovered.ts | 0 | 0 | 0 | 0 | 1-8
6262
--------------|---------|----------|---------|---------|-------------------

e2e/__tests__/__snapshots__/globals.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ FAIL __tests__/onlyConstructs.test.js
2424
Missing second argument. It must be a callback function.
2525
2626
> 1 | describe('describe, no implementation');
27-
| ^
27+
| ^
2828
29-
at Object.<anonymous> (__tests__/onlyConstructs.test.js:1:10)
29+
at Object.describe (__tests__/onlyConstructs.test.js:1:1)
3030
`;
3131
3232
exports[`cannot have describe with no implementation 2`] = `

e2e/__tests__/consoleLogOutputWhenRunInBand.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ test('prints console.logs when run with forceExit', () => {
3535
const {rest, summary} = extractSummary(stderr);
3636

3737
if (nodeMajorVersion < 12) {
38-
expect(stdout).toContain(
39-
'at Object.<anonymous>.test (__tests__/a-banana.js:1:1)',
40-
);
38+
expect(stdout).toContain('at Object.log (__tests__/a-banana.js:1:30)');
4139

4240
stdout = stdout.replace(
4341
'at Object.<anonymous>.test (__tests__/a-banana.js:1:1)',

e2e/__tests__/failures.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ test('not throwing Error objects', () => {
4242
if (nodeMajorVersion < 12) {
4343
const lineEntry = '(__tests__/duringTests.test.js:43:8)';
4444

45-
expect(stderr).toContain(`at Object.<anonymous>.done ${lineEntry}`);
45+
expect(stderr).toContain(`at Object.done ${lineEntry}`);
4646

4747
stderr = stderr.replace(
48-
`at Object.<anonymous>.done ${lineEntry}`,
48+
`at Object.done ${lineEntry}`,
4949
`at Object.<anonymous> ${lineEntry}`,
5050
);
5151
}

e2e/__tests__/nativeEsm.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test('test config is without transform', () => {
2222

2323
// The versions where vm.Module exists and commonjs with "exports" is not broken
2424
onNodeVersions('>=12.16.0', () => {
25-
test('runs test with native ESM', () => {
25+
test.skip('runs test with native ESM', () => {
2626
const {exitCode, stderr, stdout} = runJest(DIR, ['native-esm.test.js'], {
2727
nodeOptions: '--experimental-vm-modules --no-warnings',
2828
});

e2e/native-async-mock/yarn.lock

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This file is generated by running "yarn install" inside your project.
2+
# Manual changes might be lost - proceed with caution!
3+
4+
__metadata:
5+
version: 4
6+
7+
"root-workspace-0b6124@workspace:.":
8+
version: 0.0.0-use.local
9+
resolution: "root-workspace-0b6124@workspace:."
10+
languageName: unknown
11+
linkType: soft

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
"jest-jasmine": "JEST_JASMINE=1 yarn jest",
9999
"jest-jasmine-ci": "yarn jest-jasmine --color --config jest.config.ci.js",
100100
"jest-coverage": "yarn jest --coverage",
101-
"lint": "eslint . --cache --ext js,jsx,ts,tsx,md",
101+
"lint": "eslint . --fix --cache --ext js,jsx,ts,tsx,md",
102102
"lint:prettier": "prettier '**/*.{md,yml,yaml}' 'website/**/*.{css,js}' --write --ignore-path .gitignore",
103103
"lint:prettier:ci": "prettier '**/*.{md,yml,yaml}' 'website/**/*.{css,js}' --check --ignore-path .gitignore",
104104
"remove-examples": "node ./scripts/remove-examples.js",

packages/jest-runtime/src/__tests__/__snapshots__/runtime_wrap.js.snap

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)