Skip to content
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

Node response patching #266

Merged
merged 9 commits into from
Jul 16, 2020
Merged

Conversation

pmelab
Copy link
Contributor

@pmelab pmelab commented Jul 7, 2020

Changes

  • Uses node-fetch to enable response patching in Node.
  • Adds integration tests for response patching in Node.

GitHub

Roadmap

  • Ensure call signature of window.fetch and node-fetch is compatible. Line out the corner-cases and limitations.
  • Ensure that node-fetch doesn't get bundled and executed on the client

Copy link
Member

@kettanaito kettanaito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for these changes, @pmelab! I've had a few suggestions, do you mind take a look?

package.json Outdated Show resolved Hide resolved
test/msw-api/setup-server/response-patching.test.ts Outdated Show resolved Hide resolved
@pmelab
Copy link
Contributor Author

pmelab commented Jul 7, 2020

@kettanaito Thank you for the review! I did the requested changes, and CI passed.

What's open are two TODOs I left in the code: The type definitions for RequestInit and Response in the browser and node-fetch are (in theory) not fully compatible and I did not find a way to make them so. In practice, I'm pretty sure they are. As far as I can tell, cross-fetch and isomorphic-fetch simply pretend compatibility in their type definitions.

@kettanaito
Copy link
Member

Thank you for the adjustments! Looks amazing. I share your caution regarding type definition (call signature compatibility). We need to research what are the exact limitations between in-browser fetch and node-fetch, apart from environment limitation (like absolute URLs in Node). My initial assumption is that everything fetch does should be able to reproduce with http, which I assume node-fetch uses under the hood.

@pmelab pmelab marked this pull request as ready for review July 7, 2020 15:37
@pmelab pmelab requested a review from kettanaito July 7, 2020 15:59
@kettanaito kettanaito added this to the 0.20.0 milestone Jul 14, 2020
@kettanaito
Copy link
Member

Hey. I've updated the feature branch against the latest master. Also added two more integration tests that asserts bypass/fall-through behavior (the difference between using ctx.fetch and native fetch directly). I've checked and confirm that node-fetch is not required when working in a browser, and I find the call signatures of window.fetch and node-fetch compatible.

@kettanaito
Copy link
Member

Thank you for improving the library! Welcome to contributors 🎉

@kettanaito kettanaito merged commit 06ad9ab into mswjs:master Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Response patching in Node fails
2 participants