From 73e9721294e14a3194c5e3dcf20426e3c935e942 Mon Sep 17 00:00:00 2001 From: Christian Murphy Date: Tue, 29 Sep 2026 07:12:21 -0700 Subject: [PATCH] Replace `concat-stream` w/ `node:stream/consumers` Related-to: unifiedjs/unified-engine#92. --- package.json | 1 - test.jsx | 49 ++++++++++++++++++++----------------------------- 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 40ea12c..1eacf9a 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,6 @@ "@types/react": "^19.0.0", "@types/react-dom": "^19.0.0", "c8": "^12.0.0", - "concat-stream": "^2.0.0", "esbuild": "^0.28.0", "eslint-plugin-react": "^7.0.0", "global-jsdom": "^29.0.0", diff --git a/test.jsx b/test.jsx index 2dae405..0a68da4 100644 --- a/test.jsx +++ b/test.jsx @@ -19,10 +19,11 @@ */ import assert from 'node:assert/strict' +import {PassThrough} from 'node:stream' +import {text} from 'node:stream/consumers' import test from 'node:test' import 'global-jsdom/register' import {render, waitFor} from '@testing-library/react' -import concatStream from 'concat-stream' import {Component} from 'react' import {renderToPipeableStream, renderToStaticMarkup} from 'react-dom/server' import Markdown, {MarkdownAsync, MarkdownHooks} from 'react-markdown' @@ -32,8 +33,6 @@ import remarkGfm from 'remark-gfm' import remarkToc from 'remark-toc' import {visit} from 'unist-util-visit' -const decoder = new TextDecoder() - test('react-markdown (core)', async function (t) { await t.test('should expose the public api', async function () { assert.deepEqual(Object.keys(await import('react-markdown')).sort(), [ @@ -1100,37 +1099,29 @@ test('MarkdownAsync', async function (t) { }) await t.test('should support `MarkdownAsync` (2)', async function () { - return new Promise(function (resolve, reject) { - renderToPipeableStream() - .pipe( - concatStream({encoding: 'u8'}, function (data) { - assert.equal(decoder.decode(data), '

a

') - resolve() - }) - ) - .on('error', reject) - }) + const stream = new PassThrough() + + renderToPipeableStream().pipe(stream) + + assert.equal(await text(stream), '

a

') }) await t.test( 'should support async plugins w/ `MarkdownAsync` (`rehype-starry-night`)', async function () { - return new Promise(function (resolve) { - renderToPipeableStream( - - ).pipe( - concatStream({encoding: 'u8'}, function (data) { - assert.equal( - decoder.decode(data), - '
console.log(3.14)\n
' - ) - resolve() - }) - ) - }) + const stream = new PassThrough() + + renderToPipeableStream( + + ).pipe(stream) + + assert.equal( + await text(stream), + '
console.log(3.14)\n
' + ) } ) })