🐛 Bug Report
First off... thanks heaps for creating and maintaining Jest. 🙏 JavaScript testing is in a better state because of all you do! 🃏
It looks like a regression was introduced between versions 22.4.4 and 23.1.0 of Jest Circus that is causing a rather substantial memory leak (I wasn't able to run any tests with errors on any versions between those two versions):
$ npm run jest-circus
PASS __tests__/index-21.jest.js (24 MB heap size)
...
PASS __tests__/index-79.jest.js (251 MB heap size)
PASS __tests__/index-49.jest.js (253 MB heap size)
PASS __tests__/index-65.jest.js (256 MB heap size)
PASS __tests__/index-73.jest.js (258 MB heap size)
Test Suites: 100 passed, 100 total
Tests: 100 passed, 100 total
Snapshots: 0 total
Time: 13.991s
Ran all test suites.
I had a look at #7274 (comment) as well as #6965. I added this.stack = this.stack to https://github.com/facebook/jest/blob/master/packages/jest-util/src/ErrorWithStack.ts (via https://github.com/facebook/jest/blob/master/packages/jest-circus/src/index.ts) and this.stack = this.stack after every new Error() invocation in https://github.com/facebook/jest/blob/master/packages/jest-circus/src/utils.ts, which didn't seem to impact the leaks at all.
Other than narrowing down the version that introduced the regression and trying what was mentioned in #6965, I haven't really had time to make any more progress. I also noticed #7274 but that seemed to be focused on memory leaks from graceful-fs, which I confirmed independently, so I thought I would create a new issue that focuses purely on jest-circus.
To Reproduce
I created a sandbox repository with a simple test and 100 test files. I then ran the tests with jest-circus as well as the default runner for (matching) versions: 24.8.0, 23.1.0, and 22.4.4 and recorded the results: https://github.com/BuildingConnected/jest-circus-memory-leak.
Expected behavior
The memory footprint when running tests via jest-circus should match that of the default test runner.
Link to repl or repo (highly encouraged)
https://github.com/BuildingConnected/jest-circus-memory-leak
Run 100 test files:
npm run jest # default runner
npm run jest-circus # jest-circus
Run npx envinfo --preset jest
System:
OS: macOS 10.14.6
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Binaries:
Node: 10.15.1 - ~/.nvm/versions/node/v10.15.1/bin/node
Yarn: 1.17.3 - /usr/local/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v10.15.1/bin/npm
npmPackages:
jest: 24.8.0 => 24.8.0
🐛 Bug Report
First off... thanks heaps for creating and maintaining Jest. 🙏 JavaScript testing is in a better state because of all you do! 🃏
It looks like a regression was introduced between versions
22.4.4and23.1.0of Jest Circus that is causing a rather substantial memory leak (I wasn't able to run any tests with errors on any versions between those two versions):$ npm run jest-circus PASS __tests__/index-21.jest.js (24 MB heap size) ... PASS __tests__/index-79.jest.js (251 MB heap size) PASS __tests__/index-49.jest.js (253 MB heap size) PASS __tests__/index-65.jest.js (256 MB heap size) PASS __tests__/index-73.jest.js (258 MB heap size) Test Suites: 100 passed, 100 total Tests: 100 passed, 100 total Snapshots: 0 total Time: 13.991s Ran all test suites.I had a look at #7274 (comment) as well as #6965. I added
this.stack = this.stackto https://github.com/facebook/jest/blob/master/packages/jest-util/src/ErrorWithStack.ts (via https://github.com/facebook/jest/blob/master/packages/jest-circus/src/index.ts) andthis.stack = this.stackafter everynew Error()invocation in https://github.com/facebook/jest/blob/master/packages/jest-circus/src/utils.ts, which didn't seem to impact the leaks at all.Other than narrowing down the version that introduced the regression and trying what was mentioned in #6965, I haven't really had time to make any more progress. I also noticed #7274 but that seemed to be focused on memory leaks from
graceful-fs, which I confirmed independently, so I thought I would create a new issue that focuses purely onjest-circus.To Reproduce
I created a sandbox repository with a simple test and 100 test files. I then ran the tests with
jest-circusas well as the default runner for (matching) versions:24.8.0,23.1.0, and22.4.4and recorded the results: https://github.com/BuildingConnected/jest-circus-memory-leak.Expected behavior
The memory footprint when running tests via
jest-circusshould match that of the default test runner.Link to repl or repo (highly encouraged)
https://github.com/BuildingConnected/jest-circus-memory-leak
Run 100 test files:
Run
npx envinfo --preset jest