-
Notifications
You must be signed in to change notification settings - Fork 15
Description
Hi,
util:isStream
only returns 'node'
if the input is an instance of stream.Readable
, but there are many implementations of such streams that although compatible don't share the same prototype.
One of those cases is Fastify's mock HTTP requests that very conveniently allows tests to run without actually calling server.listen
. It took me a long time to understand why all my encryption-enabled unit tests were failing with OpenPGP.js throwing "Error during parsing. This message / key probably does not conform to a valid OpenPGP format", as the same code worked fine outside of Jest.
Piping all requests to a Passthrough eventually fixed my problem, but it would be nice to just let OpenPGP recognize all compatible streams as such.
Could we change the test to something along the lines of:
if (NodeReadableStream &&
(NodeReadableStream.prototype.isPrototypeOf(input) ||
input.readable || typeof input._read === 'function')) {
return 'node';
}
?
NodeReadableStream
implies isNode
so it seems safe to consider all compatible streams as being of the node kind.
Also (browser console):
> input = new ReadableStream()
> input.readable || typeof input._read === 'function'
> false
I'd be happy to submit a PR if we can agree on a good solution.
Cheers