You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When working with MSW, users experience an issue that requests may continue pending even after the tests are done. The issue itself is often caused by the user's mistake, but it's still wrong for us to keep requests alive after server.close()/interceptor.dispose() was called.
I'd be careful not to introduce "abort on close" behavior in the Interceptors, because it's not unexpected to dispose of the interceptor while still expecting the request to finish. I'm not sure at the moment what would be the default behavior here, if any.
Proposal
Some sort of unified abort API would be nice to expose from the Interceptors. I can imagine something like this:
// consumer.jsconstinterceptor=newBatchInterceptor({interceptors: [...]})interceptor.on('request',({ request, controller })=>{// Unified means to abort any intercepted request.controller.abort()})
Technical details
All currently supported request modules provide native means to achieve the abort functionality:
Technically speaking, this task is about propagating those methods up the interceptor chain, wrapping them in a nice API, and exposing that API in the argument of request listeners.
XMLHttpRequest.abort() doesn't support the reason parameter but that's okay.
I'm also considering whether we should move .respondWith() to the newly introduced controller. That way, the controller is what allows the consumer to control what to to with the intercepted request.
The text was updated successfully, but these errors were encountered:
Will keep this in mind and close in favor of #520. There are a few corner cases that make the experience around aborting requests unpredictable. I'd love to discuss those before moving forward with this feature.
Motivation
When working with MSW, users experience an issue that requests may continue pending even after the tests are done. The issue itself is often caused by the user's mistake, but it's still wrong for us to keep requests alive after
server.close()
/interceptor.dispose()
was called.I'd be careful not to introduce "abort on close" behavior in the Interceptors, because it's not unexpected to dispose of the interceptor while still expecting the request to finish. I'm not sure at the moment what would be the default behavior here, if any.
Proposal
Some sort of unified abort API would be nice to expose from the Interceptors. I can imagine something like this:
Technical details
All currently supported request modules provide native means to achieve the abort functionality:
http.ClientRequest
viarequest.destroy()
.XMLHttpRequest
viarequest.abort()
.fetch
viaAbortController.abort()
.Technically speaking, this task is about propagating those methods up the interceptor chain, wrapping them in a nice API, and exposing that API in the argument of request listeners.
Here's a draft of the controller interface:
I'm also considering whether we should move
.respondWith()
to the newly introduced controller. That way, the controller is what allows the consumer to control what to to with the intercepted request.The text was updated successfully, but these errors were encountered: