Skip to content

Commit

Permalink
fix: plug memory leak in jest-circus when running in band (#9934)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Apr 30, 2020
1 parent ad1b9dc commit 2fa7f4d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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;

0 comments on commit 2fa7f4d

Please sign in to comment.