Closed hbgl closed 8 months ago
Which approach is easier to implement and might give less backwards incompatible changes?
The Readable approach is definitely easier to implement and more backwards compatible than IncomingMessage. One might get away with extending Readable without bumping the major version. Extending IncomingMessage, on the other hand, would be more akin to a rewrite of the mock request.
Ok, then I'd prefer extending from stream.Readable
Stale issue message
In an effort to make the mock request behave more like a real http.IncomingMessage, it would make sense to extend from stream.Readable which is the base class of http.IncomingMessage). There has been PR https://github.com/eugef/node-mocks-http/pull/169 that did attempt to extend from stream.Readable but it did not properly implement the Readable protocol which led to issue https://github.com/eugef/node-mocks-http/issues/174.
I also think there is the possibility of inheriting directly from http.IncomingMessage. This would would require the mock to rely on some of Node's implementation details which have been reasonably stable. The big advantage would be that the mock could reuse a large portion of the logic, including the complicated header handling.
@eugef Which of the two options, if any, would you prefer? I would be very happy to work on a PR for this feature.