Skip to content

Commit 2fa7f4d

Browse files
authored
fix: plug memory leak in jest-circus when running in band (#9934)
1 parent ad1b9dc commit 2fa7f4d

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
- run: *install
5959
- save-cache: *save-cache
6060
- run:
61-
command: JEST_CIRCUS=1 yarn test-ci-partial
61+
command: JEST_CIRCUS=1 yarn test-ci-partial && JEST_CIRCUS=1 yarn test-leak
6262
- store_test_results:
6363
path: reports/junit
6464

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-circus]` Fix memory leak when running in band ([#9934](https://github.com/facebook/jest/pull/9934))
12+
1113
## 25.5.2
1214

1315
### Fixes

packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {JestEnvironment} from '@jest/environment';
1111
import type {TestResult} from '@jest/test-result';
1212
import type {RuntimeType as Runtime} from 'jest-runtime';
1313
import type {SnapshotStateType} from 'jest-snapshot';
14+
import {deepCyclicCopy} from 'jest-util';
1415

1516
const FRAMEWORK_INITIALIZER = path.resolve(__dirname, './jestAdapterInit.js');
1617
const EXPECT_INITIALIZER = path.resolve(__dirname, './jestExpect.js');
@@ -101,7 +102,13 @@ const jestAdapter = async (
101102
globalConfig,
102103
testPath,
103104
});
104-
return _addSnapshotData(results, snapshotState);
105+
106+
_addSnapshotData(results, snapshotState);
107+
108+
// We need to copy the results object to ensure we don't leaks the prototypes
109+
// from the VM. Jasmine creates the result objects in the parent process, we
110+
// should consider doing that for circus as well.
111+
return deepCyclicCopy(results, {keepPrototype: false});
105112
};
106113

107114
const _addSnapshotData = (
@@ -131,7 +138,6 @@ const _addSnapshotData = (
131138
results.snapshot.unchecked = !status.deleted ? uncheckedCount : 0;
132139
// Copy the array to prevent memory leaks
133140
results.snapshot.uncheckedKeys = Array.from(uncheckedKeys);
134-
return results;
135141
};
136142

137143
export = jestAdapter;

0 commit comments

Comments
 (0)