Skip to content

Commit

Permalink
stream: allow pass stream class to stream.compose
Browse files Browse the repository at this point in the history
PR-URL: nodejs#50187
Fixes: nodejs#50176
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
himself65 authored and alexfernandez committed Nov 1, 2023
1 parent 9933cdf commit 6f47330
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/internal/streams/duplexify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-runner-run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 6f47330

Please sign in to comment.