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
feat: add "req.passthrough" #1204
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 69c9e3e:
|
export function passthrough(): MockedResponse<null> { | ||
// Constructing a dummy "101 Continue" mocked response | ||
// to keep the return type of the resolver consistent. | ||
return { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm returning a MockedResponse
from passthrough
to keep the same return type of the response resolver. I don't like this approach but I'll use it for now.
We need to refactor the return type of the resolver to be some sort of Instruction
, which could be:
- Passthrough
- Fallthrough
- Use a mocked response
- Return a network error
- Anything else in the future
It should be a strictly defined object representing the library's next steps. Resolvers don't necessarily return mocked responses, as in the Passthrough/Fallthrough scenarios. Each intention can also be permanent or one-time (like res.once()
). This is a great opportunity to solve #413.
The source for these instructions can also differ:
res()
instructs to use a mocked response.req.passthrough()
instructs to passthrough this request.res.networkError()
(or a different API) instructs to return a network error.
Decoupling the source from the instruction will allow us to design semantic APIs without locking ourselves in a MockedResponse
structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposing this in #1207.
1c522cd
to
69c9e3e
Compare
Sweet! Where are the docs for this? |
@kentcdodds, I've added the documentation in mswjs/mswjs.io#192. |
When is this coming in formal release? |
@abhishekarun, as soon as #1175 is addressed. If you have some spare time I'd certainly appreciate some help with that issue. Also, keep in mind that this is not a new feature but rather an improvement over the existing bypass/passthrough behavior. |
Released: v0.40.0 🎉This has been released in v0.40.0! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |
This PR seems to break the compatibility with |
I would politely suggest @kettanaito that the release notes for this release mention this as a breaking change. |
@taylorkline, updated. Breaking changes between minor releases in pre-1.0 packages are implied but I agree this should've been communicated better. |
Thank you! |
Changes
req.passthrough
to explicitly instruct MSW to perform an intercepted request as-is.undefined
/null
from handlers now treats the request as unhandled.