-
-
Notifications
You must be signed in to change notification settings - Fork 119
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(ClientRequest): use proxies for interception #265
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kettanaito
commented
Feb 16, 2023
export const kOtherSide = Symbol('kOtherSide') | ||
const kCallback = Symbol('kCallback') | ||
|
||
export class DuplexPair { |
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.
Boy have I gone into depth here. Brgh.
Good for reference, not so much for production. Superseded by #515. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a third generation of the request interception algorithm. To improve on the previous class augmentation principle, we are introducing proxies. Proxies allow us to keep the original request modules implementations intact while spying only on specific scenarios of properties/methods of those classes.
Motivation
This should increase the integrity of the tested code even further since there are even fewer things that are mocked right now. We reduce the surface of mocks/spies to the minimum. Less mock code also means better performance and resilience of the entire approach, which benefits our users in the form of faster tests and production-grade requests behavior.
Because this change moves the response resolution to a mock
Agent
instance, we can control the underlying socket connection and ignore it entirely if there's mock. Previously, we recorded any socket/request errors during this connection and replayed them in the case where there weren't any mocks.Roadmap
requestUrl
from the mock agents. They cannot know about individual requests, they receive request info inaddRequest
. Consider parsing the request there instead? Doesn't look like we care aboutoptions
andcallback
now with proxies.uuid4
with the alternative (see MSW).