Closed kettanaito closed 2 months ago
That's a good one!
This is somewhat related to https://github.com/mswjs/msw/issues/1804. If the mentioned API is implemented on MSW's side, we should use it for query parameter predicates. The idea behind a new API is to allow the developer to introduce request predicates before the parsing phase of the request handler. This yields better performance.
But we shouldn't wait for that one to land. We can implement the predicate within the response resolver for now, that will also work.
@weyert, please, would you be interested in tackling this task? I will help with the code reviews and seeing it released. Let me know!
@weyert, please, would you be interested in tackling this task? I will help with the code reviews and seeing it released. Let me know!
Sure, I can have a look in the coming days. I have to complete some work stuff first.
This has been released in v0.2.0!
Make sure to always update to the latest version (npm i @mswjs/source@latest
) to get the newest features and bug fixes.
Predictable release automation by @ossjs/release.
MSW removes query parameters from request URLs. We need to take those into account during the request handler generation. Most likely, to create a custom predicate with a order-insensitive match for the query parameters.
Current behavior
If the recorded traffic contains requests with query parameters, those will be stripped away by MSW (intended behavior). However, they must be respected in order to match the right requests in the generated handlers.
Expected behavior
If the recorded request has query parameters, those are translated into a predicate function within the response resolver that only matches the same requests in tests/runtime.