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

feat(ClientRequest): use proxies for interception #265

Closed
wants to merge 24 commits into from

Conversation

kettanaito
Copy link
Member

@kettanaito kettanaito commented Jun 25, 2022

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

  • Finish logging for the new interception.
  • Remove requestUrl from the mock agents. They cannot know about individual requests, they receive request info in addRequest. Consider parsing the request there instead? Doesn't look like we care about options and callback now with proxies.
  • Replace uuid4 with the alternative (see MSW).

@kettanaito kettanaito changed the title chore: use proxy over "http.get" and "MockHttpAgent" feat: use proxy to spy on request modules Jun 25, 2022
@kettanaito kettanaito changed the title feat: use proxy to spy on request modules feat(ClientRequest): use proxies for interception Jun 25, 2022
export const kOtherSide = Symbol('kOtherSide')
const kCallback = Symbol('kCallback')

export class DuplexPair {
Copy link
Member Author

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.

@kettanaito
Copy link
Member Author

Good for reference, not so much for production. Superseded by #515.

@kettanaito kettanaito closed this Apr 17, 2024
@kettanaito kettanaito deleted the feat/use-reflectors branch April 17, 2024 08:25
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.

None yet

1 participant