mswjs / interceptors

Low-level network interception library.
https://npm.im/@mswjs/interceptors
MIT License
537 stars 123 forks source link

Propagate socket error event on res.destroy #449

Closed mikicho closed 2 months ago

mikicho commented 11 months ago

According to docs, response.destroy(err) emits error event.:

If error is provided, an 'error' event is emitted on the socket and error is passed as an argument to any listeners on the event.

https://github.com/nodejs/node/blob/main/lib/internal/streams/destroy.js#L136


Nock handles this by overriding the Socket class and propagate the event to the request.

@kettanaito I tried to open a PR for this but couldn't understand how to do this, but I believe I'll be able to with your direction.

mikicho commented 11 months ago

Update: the response behavior isn't identical to the original response. IncomingMessage and PassThrough act differently on destroy image

mikicho commented 11 months ago

@kettanaito Why do we skip properties if they have the same name? The implementation may be still different If I delete these lines my test passes because it calls to the correct implementation.

kettanaito commented 2 months ago

Released: v0.32.1 🎉

This has been released in v0.32.1!

Make sure to always update to the latest version (npm i @mswjs/interceptors@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.