jest: Memory leak when using --coverage flag
bug
What is the current behavior?
When running our test suites with --coverage
memory seems to leak, and heap size increases with ~13MB per test suite (we have a total of 240 test suites), ultimately causing Jest to slow down (as mentioned in other memory leak issues)
If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install
and yarn test
.
Unfortunately we can’t provide the actual code from our tests, but all we have to do is enable --coverage
to get the above behavior.
What is the expected behavior?
We would expect some overhead, but 13MB per test suite is causing our CI to timeout and make the coverage flag unusable.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
node@6.9.4
, yarn@0.19.1
, jest@19.1.0-alpha-eed82034
, Mac OSX v10.12.3
"jest": {
"setupFiles": [
"<rootDir>/src/setup.js"
],
"setupTestFrameworkScriptFile": "<rootDir>/jest-setup.js",
"roots": [
"<rootDir>/src"
],
"testEnvironment": "node",
"testPathIgnorePatterns": [
"/node_modules/"
],
"coverageThreshold": {
"global": {
"branches": 60,
"functions": 80,
"lines": 80,
"statements": 80
}
}
}
I’ve masked the real path… so this is actually different files:
node --expose-gc $(BIN)/jest --no-cache --i --logHeapUsage
PASS $/__tests__/test.js (71 MB heap size)
PASS $/__tests__/test.js (71 MB heap size)
PASS $/__tests__/test.js (71 MB heap size)
PASS $/__tests__/test.js (71 MB heap size)
PASS $/__tests__/test.js (71 MB heap size)
PASS $/__tests__/test.js (71 MB heap size)
PASS $/__tests__/test.js (71 MB heap size)
PASS $/__tests__/test.js (72 MB heap size)
PASS $/__tests__/test.js (72 MB heap size)
PASS $/__tests__/test.js (71 MB heap size)
PASS $/__tests__/test.js (74 MB heap size)
PASS $/__tests__/test.js (71 MB heap size)
PASS $/__tests__/test.js (72 MB heap size)
PASS $/__tests__/test.js (78 MB heap size)
PASS $/__tests__/test.js (78 MB heap size)
node --expose-gc $(BIN)/jest --coverage --no-cache --i --logHeapUsage
PASS $/__tests__/test.js (139 MB heap size)
PASS $/__tests__/test.js (151 MB heap size)
PASS $/__tests__/test.js (164 MB heap size)
PASS $/__tests__/test.js (177 MB heap size)
PASS $/__tests__/test.js (189 MB heap size)
PASS $/__tests__/test.js (202 MB heap size)
PASS $/__tests__/test.js (215 MB heap size)
PASS $/__tests__/test.js (228 MB heap size)
PASS $/__tests__/test.js (240 MB heap size)
PASS $/__tests__/test.js (253 MB heap size)
PASS $/__tests__/test.js (265 MB heap size)
PASS $/__tests__/test.js (278 MB heap size)
PASS $/__tests__/test.js (291 MB heap size)
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 2
- Comments: 19 (9 by maintainers)
I’ll try to make a small repro, but probably won’t have the time before Tuesday.
We are reducing memory for coverage in Jest 21 (
jest@test
) but further leaks are probably not something we’ll look at anytime soon. If you’d like to investigate further, please send us PRs with fixes 😃 Thank you.@danieljuhl any news on the repro?
@oshalygin see: https://github.com/tmpvar/jsdom/issues/1682#issuecomment-276774388
@danieljuhl any updates? Can you also try if it happens on Jest 20?
I can repro it with the Jest repo, although I get a similar behavior without
--coverage
With coverage
Without coverage