Memory leaked when requiring nock
See original GitHub issueWhat is the expected behavior?
Nock should not keep any references that leaks memory.
What is the actual behavior?
Nock leaks memory as soon as it is require
d in a test.
How to reproduce the issue
Repro files: https://gist.github.com/avaly/8965470dfc5891836e57e2f95933f3cd
$ jest --detectLeaks
FAIL ./sum.test.js
● Test suite failed to run
EXPERIMENTAL FEATURE!
Your test suite is leaking memory. Please ensure all references are cleaned.
There is a number of things that can leak memory:
- Async operations that have not finished (e.g. fs.readFile).
- Timers not properly mocked (e.g. setInterval, setTimeout).
- Keeping references to the global scope.
at node_modules/jest-cli/build/TestScheduler.js:240:24
As soon as the require('nock');
line is removed/commented out:
$ jest --detectLeaks
PASS ./sum.test.js
✓ adds 1 + 2 to equal 3 (2ms)
Versions
Software | Version(s) |
---|---|
Nock | 10.0.6 |
Node | 8.15.0 |
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Getting Jest + Nock under control
This is just a short tale on how I fixed some of the memory leaking issues we can face with Jest and Nock,...
Read more >Your Jest Tests are Leaking Memory
Why does Jest leak memory? Jest resets the require cache between each test run. This is really nice because it gives test suites...
Read more >Calling nock.restore() after each test suite doesn't stop ...
Calling nock.restore() after each test suite doesn't stop memory leak.
Read more >Memory leak - Wikipedia
In computer science, a memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations in...
Read more >Would this be considered a memory leak? - Stack Overflow
@Nick: The source of the memory (stack, heap, static) is irrelevant to the OS--it's all just memory, and it will be replaced and...
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
just for anyone coming across this today, it’s possible to clear up the leak by putting the following either in your test file or in your jest entry point:
I’m going to unpin this. Without a minimal test case, or even a very small test case with Jest, it’s hard to act on this.