From 789372a0721ec0086c3292ad558b3e06124d272d Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Sat, 14 Oct 2023 17:04:43 -0500 Subject: [PATCH] stream: allow pass stream class to `stream.compose` PR-URL: https://github.com/nodejs/node/pull/50187 Fixes: https://github.com/nodejs/node/issues/50176 Reviewed-By: Moshe Atlow Reviewed-By: Robert Nagy Reviewed-By: Benjamin Gruenbaum --- lib/internal/streams/duplexify.js | 5 +++++ test/parallel/test-runner-run.mjs | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/internal/streams/duplexify.js b/lib/internal/streams/duplexify.js index 788bcb63242c38..2503b531519066 100644 --- a/lib/internal/streams/duplexify.js +++ b/lib/internal/streams/duplexify.js @@ -85,6 +85,11 @@ module.exports = function duplexify(body, name) { if (typeof body === 'function') { const { value, write, final, destroy } = fromAsyncGen(body); + // Body might be a constructor function instead of an async generator function. + if (isDuplexNodeStream(value)) { + return value; + } + if (isIterable(value)) { return from(Duplexify, value, { // TODO (ronag): highWaterMark? diff --git a/test/parallel/test-runner-run.mjs b/test/parallel/test-runner-run.mjs index 3201da25f87a1d..0d7aa346409647 100644 --- a/test/parallel/test-runner-run.mjs +++ b/test/parallel/test-runner-run.mjs @@ -96,6 +96,16 @@ describe('require(\'node:test\').run', { concurrency: true }, () => { assert.match(stringResults[1], /tests 1/); assert.match(stringResults[1], /pass 1/); }); + + it('spec', async () => { + const result = await run({ + files: [join(testFixtures, 'default-behavior/test/random.cjs')] + }).compose(spec).toArray(); + const stringResults = result.map((bfr) => bfr.toString()); + assert.match(stringResults[0], /this should pass/); + assert.match(stringResults[1], /tests 1/); + assert.match(stringResults[1], /pass 1/); + }); }); it('should be piped with tap', async () => {