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
nock.cleanAll() doesn't stop delayed requests #1118
Comments
I agree, it’d be great if it would clean out all timeouts. I’d happy to review a PR if you or anyone else would like to give it a go. A PR with a failing test would already be a great start, we can take it from there |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Per nock/nock#1118, `cleanAll()` isn't cleaning up timers. Speed these up, to prevent mocha from hanging at the end of tests.
There are a few solutions to this one is a simple hack for this which would clear all setTimeouts in the queue but that obviously would include ones not created by nock, not ideal. The other solution would require a singleton which stores all timeout ids which nock creates. |
Thanks @TLPcoder for opening a PR to address this! 🙌 I'm re-tagging this as a feature, as I'm not sure this functionality belongs in
It's looking like this will be resolved by adding a new lifecycle method called e.g. |
🎉 This issue has been resolved in version 11.6.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
One of the tests were using nock's `delay()` to simulate timeouts but these requests were still hanging around after the tests finish running causing the following warning/error (and some small delay): > Jest did not exit one second after the test run has completed. > This usually means that there are asynchronous operations that weren't > stopped in your tests. Consider running Jest with --detectOpenHandles > to troubleshoot this issue. The solution is to abort all pending requests after this tests run as suggested in this nock issue: nock/nock#1118 (we call `nock.cleanAll()` after each test but this doesn't abort the those pending delayed requests)
One of the tests were using nock's `delay()` to simulate timeouts but these requests were still hanging around after the tests finish running causing the following warning/error (and some small delay): > Jest did not exit one second after the test run has completed. > This usually means that there are asynchronous operations that weren't > stopped in your tests. Consider running Jest with --detectOpenHandles > to troubleshoot this issue. The solution is to abort all pending requests after this tests run as suggested in this nock issue: nock/nock#1118 (we call `nock.cleanAll()` after each test but this doesn't abort the those pending delayed requests)
Environment info
Code example
The following code example demonstrates that
nock.cleanAll()
call doesn't remove delayed requests from Node.js event loop:Actual behavior
Node.js process waits while 5 seconds timeout will be reached:
Expected behavior
nock.cleanAll()
method removes all request timeouts.More information
This causes problem with
mocha >= 4.0.0
, because Mocha will no longer force the process to exit once all tests complete. See https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#default-behavior.Related issues
The text was updated successfully, but these errors were encountered: