Repeated interception when requests are made within Promise.all()
See original GitHub issueWhat is the expected behavior?
Interceptors are not persisted by default, which means that only one request will be matched and others should throw an error No match for request
.
What is the actual behavior?
If requests are made within Promise.all()
and registered interceptor is defined with reply with callback, it handles multiple requests. See the demonstrations below.
How to reproduce the issue
Issue reproduced where 3 requests are successful: Interceptor with reply callback Correct behavior with error thrown: Interceptor without reply callback
Does the bug have a test case?
I expect it does not have.
Versions
Software | Version(s) |
---|---|
Nock | 12.0.1 |
Node | 10 |
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Promise.all() - JavaScript - MDN Web Docs
The Promise.all() method is one of the promise concurrency methods. It can be useful for aggregating the results of multiple promises.
Read more >How to use JavaScript Promise.all with real-life code example
JavaScript's Promise. all() method takes in a parameter of iterable promises runs them concurrently then returns a single Promise that resolves ...
Read more >Axios/Vue - Prevent axios.all() to keep executing
Promise.all is rejected if any of the elements are rejected. For example, if you pass in four promises that resolve after a timeout...
Read more >Aggregate Multiple API Requests with Promise.all()
Promise. all() takes an iterable (an array) of promises. It returns an array containing each promise resolution in the same order.
Read more >Complete Guide to Axios HTTP Client - Reflectoring
Axios is also a promise-based HTTP client that can be used in plain ... we are making requests to two APIs using the...
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
Given the fixes to the timing and event handling for v13, I’m not surprised unfortunately.
To fix this bug, we need the call to
Interceptor.markConsumed
to happen in the same microtask execution as the Interceptor matching that occurs instartPlayback
. Currently, there is asetImmediate
and an abort check between the two (ref).I think we can simply move the call to
markConsumed
out ofstart
and have it called just before the “finish” event is called on the request, here. I’ve started to write some tests, but I need to the day-job thing now. (I’m using this comment as notes to myself, sorry for any ramblings…) Off the top of my head, I assume movingmarkConsumed
will work. The effect it will have is that request that is immediately aborted will consume an Interceptor, whereas before it didn’t until a full cycle of the event loop. But, I might argue this is also a bug anyway.@mastermatt thank you for the quick fix 🎉