-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
fix(ClientRequest): support ClientRequest
constructor
#692
base: main
Are you sure you want to change the base?
Conversation
const resolver = vi.fn<HttpRequestEventMap['request']>() | ||
|
||
const interceptor = new ClientRequestInterceptor() | ||
interceptor.on('request', resolver) |
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 actually grew to dislike this pattern. Sorry it's still present in the test suite. It leads to a shared state in a shape of the resolver
function, and that's really bad.
May I please ask you to add the request listener within the test instead? It will yield a much simpler setup. Thanks!
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.
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 think so!
And please add interceptor.removeAllListeners()
to the afterEach()
hook.
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.
This looks great. I cannot believe we ignored the constructor itself. Thanks for fixing this, @mikicho!
I left one comment about the test, otherwise good.
ClientRequest
constructor
I'm thinking, will patching I may be wrong about this. Would love to hear your thoughts on this. Also, I think we need tests for this anyway to have clear expectations toward how this should behave. Since the if (options.agent instanceof MockHttpAgent) {
return Reflect.appy(...)
}
const agent = new MockHttpAgent()
return Reflect.apply(...) |
It also came to mind, but when I removed the |
That is a great find. I also thought of some cases when we should keep the
|
In runtime or in a test?
Same as what? We create a new it('..', async () => {
const req = http.request(..);
const clientReq = new ClientRequest(..);
req.agent.name === clientReq.agent.name?
}) I'm not sure what we are trying to check here. |
No description provided.