question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calling nock.restore() after each test suite doesn't stop memory leak

See original GitHub issue

What is the expected behavior?

Hi there, I am a jest user.

  beforeEach(() => {
    if (!nock.isActive()) {
      nock.activate();
    }
  });

  afterEach(() => {
    nock.cleanAll();
    nock.restore();
  });

calling this block should stop memory leak.

What is the actual behavior?

When I checkout the heap size usage by running node --expose-gc ./node_modules/.bin/jest --runInBand --logHeapUsage <DIR> I can still see the heap size gradually increased around 30MB after finishing a test file until it reached to the limit of memory capacity by V8 and shutdown the testing process.

Possible solution

Please if some of you resolved this leak by using nock.store, share what exactly you do, I do really appreciate it.

How to reproduce the issue

Runkit: Example link

Having problem producing a test case? Try and ask the community for help. If the test case cannot be reproduced, the Nock community might not be able to help you.

Does the bug have a test case?

Versions

Software Version(s)
Nock 13.0.4
Node 12.18.3
TypeScript

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mastermattcommented, Nov 11, 2021

@adamchenwei no one was able to provide a minimal example repo which exhibits the leak. We’ve yet to see actual confirmation that there is a memory leak. I’m not saying there isn’t one, but several of us have tried to reproduce it without success. Any insight you can provide from your issues are welcome.

0reactions
gr2mcommented, Jul 19, 2022

Else I can just make a new issue and reference this

that would be preferable, thank you! Thank you for creating the repository to reproduce the issue, very helpful!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Calling nock.restore() after each test suite doesn't stop ...
Calling nock.restore() after each test suite doesn't stop memory leak ... What is the expected behavior? Hi there, I am a jest user....
Read more >
Cannot find memory leak in my Express.js Jest tests
TCPSERVERWRAP means there is some connection(listener) that still remains after executing tests. Let's check buildDocument() function call, does ...
Read more >
nock reset between tests | The AI Search Engine You Control
Is there a way to reset the interceptor queue after all interceptors have been used, eg an .after() after the last inceptor and...
Read more >
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 >
Nock: HTTP Server Mocking and Expectations Library for Node.js
When invoked with this option, Nock will not match the request if any of ... Memory issues can be avoided by calling nock.restore()...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found