Single test file causing "heap out of memory"
See original GitHub issue🐛 Bug Report
Jest is crashing when running a single test file. Example failing CI log can be found here.
Issue seems to be related to the following function being called many times:
const waitForAsync = (delay = 20) => new Promise(resolve => setTimeout(resolve, delay));
To Reproduce
- Checkout the branch
git clone https://github.com/andyrichardson/tipple.git
cd tipple
git checkout 03819cf06bd9a750d7958c5d0332607d6d3860ce
- Run tests
npm run test -- --watch useFetch
Expected behavior
Tests run and at the very worst, fail.
Actual behaviour
Tests crash and don’t terminate until a heap error.
Link to repl or repo (highly encouraged)
See above
Additional info
-
Commenting out the
await waitForAsync();
calls on lines 234/237 causes the test to complete -
Running any tests in isolation causes tests to complete
-
Calling
global.gc()
after each test does not resolve the issue.
Run npx envinfo --preset jest
Note: this is failing on macOS and Linux
Paste the results here:
System:
OS: macOS 10.14.5
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Binaries:
Node: 8.12.0 - ~/.nvm/versions/node/v8.12.0/bin/node
Yarn: 1.12.3 - ~/.nvm/versions/node/v8.12.0/bin/yarn
npm: 6.9.0 - ~/.nvm/versions/node/v8.12.0/bin/npm
npmPackages:
jest: 24.8.0 => 24.8.0
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:12
Top Results From Across the Web
My Jests tests are leaking memory, how can I fix this?
First of all, make sure that you have leaky tests by running jest with the option: jest --logHeapUsage. Run your tests and check...
Read more >How to Fix JavaScript Heap Out of Memory Error - MakeUseOf
This error usually occurs when the default memory allocated by your system to Node. js is not enough to run a large project....
Read more >Finding the cause of a memory leak in Jest tests
You have to run the tests sequentially ( --runInBand ) and log heap usage ( --logHeapUsage ). Below is an excerpt of the...
Read more >Your Jest Tests are Leaking Memory
For many test suites this isn't a problem because even if tests leak memory, the tests don't use enough memory to actually cause...
Read more >JavaScript Heap Out Of Memory Error | Felix Gerschau
This error indicates high memory usage or a memory leak in your application. In this article, I cover different solutions to this problem....
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
Wanted to follow up on this - I’ve seen problem on many different projects since reporting this (my own and other people’s).
Pretty sure it’s a memory leak - #7874
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.