From d4cb0275fadad17204a2da70a88787b85c9f8d9c Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Sat, 14 Oct 2023 17:04:43 -0500 Subject: [PATCH 1/2] stream: allow pass stream class to `stream.compose` --- 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..cf609d28eed910 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..344aec66116193 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 () => { From 83cf4248107a509b94260fbdaf810dbc1c29e328 Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Sat, 14 Oct 2023 17:43:19 -0500 Subject: [PATCH 2/2] fixup! fix: lint --- lib/internal/streams/duplexify.js | 2 +- test/parallel/test-runner-run.mjs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/streams/duplexify.js b/lib/internal/streams/duplexify.js index cf609d28eed910..2503b531519066 100644 --- a/lib/internal/streams/duplexify.js +++ b/lib/internal/streams/duplexify.js @@ -85,7 +85,7 @@ 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. + // Body might be a constructor function instead of an async generator function. if (isDuplexNodeStream(value)) { return value; } diff --git a/test/parallel/test-runner-run.mjs b/test/parallel/test-runner-run.mjs index 344aec66116193..0d7aa346409647 100644 --- a/test/parallel/test-runner-run.mjs +++ b/test/parallel/test-runner-run.mjs @@ -105,7 +105,7 @@ describe('require(\'node:test\').run', { concurrency: true }, () => { 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 () => {