Memory leak issue with jest
See original GitHub issueWhat is the expected behavior? Node heap size shouldn’t grow in every test.
What is the actual behavior? Heap size increases after every test file.
With nock:
PASS test/function-86.js (22 MB heap size)
PASS test/function-75.js (22 MB heap size)
PASS test/function-1.js (22 MB heap size)
PASS test/function-43.js (26 MB heap size)
PASS test/function-24.js (26 MB heap size)
...
PASS test/function-48.js (133 MB heap size)
PASS test/function-82.js (137 MB heap size)
PASS test/function-87.js (137 MB heap size)
PASS test/function-20.js (137 MB heap size)
PASS test/function-79.js (140 MB heap size)
Test Suites: 100 passed, 100 total
Tests: 100 passed, 100 total
Snapshots: 0 total
Time: 25.506s, estimated 26s
Without nock:
PASS test/function-86.js (19 MB heap size)
PASS test/function-75.js (19 MB heap size)
PASS test/function-1.js (19 MB heap size)
PASS test/function-65.js (19 MB heap size)
PASS test/function-96.js (19 MB heap size)
...
PASS test/function-93.js (20 MB heap size)
PASS test/function-61.js (20 MB heap size)
PASS test/function-49.js (20 MB heap size)
PASS test/function-87.js (20 MB heap size)
PASS test/function-79.js (20 MB heap size)
Test Suites: 100 passed, 100 total
Tests: 100 passed, 100 total
Snapshots: 0 total
Time: 27.079s
How to reproduce the issue
Even a single require/import of nock seems to cause the issue.
Minimal test case: https://github.com/juhosuominen/jest-nock-memory-leak
Versions
Software | Version(s) |
---|---|
Nock | 11.7.0 |
Node | 11.15.0 |
Issue Analytics
- State:
- Created 4 years ago
- Reactions:9
- Comments:21 (13 by maintainers)
Top Results From Across the Web
Your Jest Tests are Leaking Memory
Jest is designed in a way that makes memory leaks likely if you're not actively trying to squash them. For many test suites...
Read more >Finding the cause of a memory leak in Jest tests
Memory leaks can be nasty and pretty hard to find. We found that the hard way. We should always make sure to clean...
Read more >Jest memory leak issue - Stack Overflow
I am running jest unit and integrations tests on my NodeJS api, I am facing some issue with possible memory leak. I tried...
Read more >Jest Memory Leaks - Some Lessons Learnt - Lukas Spiss
There seems to be a bug, introduced with Node v16.11, causing memory leaks with Jest. While this bug is certainly putting my Node...
Read more >[Bug]: Memory consumption issues on Node JS 16.11.0+ ...
Since Jest calls global.gc() when Garbage Collector is exposed and --logHeapUsage flag is present, the memory usage should be stable.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This still seems to be an issue, though I can confirm that when I use node
11.15.0
and jest^26
that there is no leak. As soon as I upgrade to node 16 (16.10.0) this is an issue again https://github.com/nock/nock/issues/2383The discussion in Jest https://github.com/facebook/jest/issues/6814
And a nice write up on it. https://chanind.github.io/javascript/2019/10/12/jest-tests-memory-leak.html