eugef / node-mocks-http

Mock 'http' objects for testing Express,js, Next.js and Koa routing functions
Other
755 stars 134 forks source link

Request async iterator #278

Closed hbgl closed 1 year ago

hbgl commented 1 year ago

Resolves issue https://github.com/eugef/node-mocks-http/issues/277

Implement the async iterator protocol for mock request.

The request emits a new custom event 'async_iterator' after a new async iterator is created. Async iterators are generally created lazily on demand. The async iterator will only yield data that is sent after it has been created since the request does not have an internal buffer (unlike stream.Readable). Without the new event it would be hard to know when exactly it is okay send data because you might sent it before the async iterator has been created. Check this test case for how to use the new event.

eugef commented 1 year ago

Hi @hbgl thank you for the contribution. Published in version 1.13.0

s100 commented 1 year ago

FYI, this change broke support for Node.js 8, so we're pinning to 1.12.2. Bet you didn't think anyone was still using Node.js 8, huh? 😁 We have some extremely old legacy packages which use Node.js 8, which we still rebuild from time to time. Not a big deal of course! Just thought you might be interested to know.

eugef commented 1 year ago

Hi @s100 thanks for reporting the issue, but we do not support Node.js 8 anymore. All features are only tested for Node.js 14 and above