-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Support MockAgent for non-undici requests as well #51979
Comments
I would certainly love to see Node.js shipping with a built-in network observation/interception API. However, I'm not sure if the The only way to achieve a good experience when mocking APIs is to leave the client code intact. This is why we've spent half a decade already at MSW refining the interception of requests in Node.js. The current state of working with the network in that regard in Node.js is a bit disjoined. We have Undici, which is the global fetch, and its Moreover, the network doesn't end at HTTP. If we are approaching this as a solution that'd work for years, I'd highly suggest we consider non-HTTP protocols as well. That likely means designing an API that hooks into the We also have to consider the mocking capabilities of such API. It's not only about observing the network but also allowing that API to emulate connections where they'd otherwise errored/timeout/failed. This bit makes it trickier. |
The custom global |
On a slightly less relevant note, we have to consider cross-environment compatibility. A third-party mocking module that relies on |
There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the
never-stale
|
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment. For more information on how the project manages feature requests, please consult the feature request management document. |
What is the problem this feature will solve?
For many years Nock and other libraries have provided HTTP mocking capabilities for testing by monkey patching Node (e.g. http.request/get functions, Socket class, etc).
Monkey patching is a technique used in Node to override certain functions or properties. While it can be useful, it also has its downsides. One of them is that it increases the maintenance burden on the library creators, who now have to update their library every time Node changes. Additionally, monkey patching can decrease the accuracy and reliability of these libraries.
What is the feature you are proposing to solve the problem?
Add undici MockAgent-like API for
ClientRequest,
which let users and library creators to intercept HTTP requests efficiently and reliably.What alternatives have you considered?
http.globalAgent
, but I'm not sure it would work or be easy.The text was updated successfully, but these errors were encountered: