eugef / node-mocks-http

Mock 'http' objects for testing Express routing functions
Other
747 stars 131 forks source link

No way to get data written to response #304

Open yepitschunked opened 1 week ago

yepitschunked commented 1 week ago

I have some code which both writes to the response directly (using res.write) and also pipes some data to the response (using otherStream.pipe(res). The problem is that for some reason this library keeps track of Buffers and strings separately:

https://github.com/eugef/node-mocks-http/blob/5ab3de26a80bdbab04a7161a23a3df7bbaacbd53/lib/mockResponse.js#L351-L366

As a result, there's no way to piece back together the data that was written. _getBuffer/_getChunks sends only the Buffers that were written and not the string content, and vice versa. There's no way to reconstruct the original order either, since Buffers and string writes could've been interleaved.