-
Notifications
You must be signed in to change notification settings - Fork 759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jest --detectleaks shows memory leak while using SuperTest with Express #634
Comments
@fakekamrankhan Both beforeAll((done) => {
port = 3000;
server = new express().listen(port, done);
});
afterAll((done) => {
server.close(done);
}) |
Thanks for the response! That is one of the many variations I did try in my troubleshooting to close off functions before Jest prematurely exits but it still complains of memory leak. I just tried the code you mentioned and it is still throwing the same error. Both of these triggers Jest to complain of memory leak:
|
Any updates on this? |
Still the same problem! :( |
Any update on this issue? |
1 similar comment
Any update on this issue? |
Given the last reproduction example sent by @fakekamrankhan (which only involves express). Seems unlikely that this is an issue with this library. |
@jonathansamines I'm actually not sure that that's the case. I was able to reproduce this issue with Koa since I was passing it an instance of the (previously started) server. I've submitted PR #651 which completely fixed my issue. |
In case you guys haven't looked in the jest issues, it looks like this is occurring because one of the modules you're using is mutating a native node module, eg. http, https, etc. I drove myself crazy hunting down this issue in my integration tests; the culprit turned out to a library called follow-redirects. It was mutating the http and https modules. |
Interesting. Is it solved in |
Still an issue in 2021 👎 |
I don't think this is the bottom of it. I've tried the most basic setup (empty project with |
For anyone seeing this now, I do not see a handle leaking in my supertest jest tests to which I pass an already constructed express app instance. |
Hey everyone,
I have been experiencing memory leaks in any test files that require supertest when using Jest with the
--detectLeaks
option on an express server.Versions
node: 12.16.1
node: 6.14.2
Modules
jest: 25.1.0
supertest: 4.0.2
weak-napi: 1.0.3 (jest complains without this module available when using
detectLeaks
)express: 4.17.1
To isolate the issue from any custom development code in my particular application, I have created this repository to highlight the problem:
https://github.com/fakekamrankhan/express-supertest-jest-detect-memory-leak
If you run
npm test
you'll see the memory leak warning. Removing supertest gets rid of the memory leak flag. The test.js file in question:The error:
I have been wracking by brain for the last four days trying to pinpoint the issue. Does anyone know if this could be anything in the test or if this is a bug in superest or jest?
The text was updated successfully, but these errors were encountered: