Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: plug memory leak in jest-circus when running in band #9934

Merged
merged 3 commits into from Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -58,7 +58,7 @@ jobs:
- run: *install
- save-cache: *save-cache
- run:
command: JEST_CIRCUS=1 yarn test-ci-partial
command: JEST_CIRCUS=1 yarn test-ci-partial && JEST_CIRCUS=1 yarn test-leak
- store_test_results:
path: reports/junit

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,8 @@

### Performance

- `[jest-circus]` Fix memory leak when running in band ([#9934](https://github.com/facebook/jest/pull/9934))

## 25.5.2

### Fixes
Expand Down
10 changes: 8 additions & 2 deletions packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts
Expand Up @@ -11,6 +11,7 @@ import type {JestEnvironment} from '@jest/environment';
import type {TestResult} from '@jest/test-result';
import type {RuntimeType as Runtime} from 'jest-runtime';
import type {SnapshotStateType} from 'jest-snapshot';
import {deepCyclicCopy} from 'jest-util';

const FRAMEWORK_INITIALIZER = path.resolve(__dirname, './jestAdapterInit.js');
const EXPECT_INITIALIZER = path.resolve(__dirname, './jestExpect.js');
Expand Down Expand Up @@ -101,7 +102,13 @@ const jestAdapter = async (
globalConfig,
testPath,
});
return _addSnapshotData(results, snapshotState);

_addSnapshotData(results, snapshotState);

// We need to copy the results object to ensure we don't leaks the prototypes
// from the VM. Jasmine creates the result objects in the parent process, we
// should consider doing that for circus as well.
return deepCyclicCopy(results, {keepPrototype: false});
};

const _addSnapshotData = (
Expand Down Expand Up @@ -131,7 +138,6 @@ const _addSnapshotData = (
results.snapshot.unchecked = !status.deleted ? uncheckedCount : 0;
// Copy the array to prevent memory leaks
results.snapshot.uncheckedKeys = Array.from(uncheckedKeys);
return results;
};

export = jestAdapter;