From f2dfe0fa800ce448cb98e7a4da2e40458fc4238d Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Tue, 16 Jan 2024 16:49:45 +0100 Subject: [PATCH] test: add regression test for 51586 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matteo Collina PR-URL: https://github.com/nodejs/node/pull/51491 Reviewed-By: Vinícius Lourenço Claro Cardoso Reviewed-By: Marco Ippolito Reviewed-By: Matthew Aitken Reviewed-By: Rafael Gonzaga Reviewed-By: Moshe Atlow Reviewed-By: Franziska Hinkelmann Reviewed-By: Benjamin Gruenbaum --- ...ebstream-structured-clone-no-leftovers.mjs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test/parallel/test-webstream-structured-clone-no-leftovers.mjs diff --git a/test/parallel/test-webstream-structured-clone-no-leftovers.mjs b/test/parallel/test-webstream-structured-clone-no-leftovers.mjs new file mode 100644 index 00000000000000..e8af095cce18d5 --- /dev/null +++ b/test/parallel/test-webstream-structured-clone-no-leftovers.mjs @@ -0,0 +1,28 @@ +import '../common/index.mjs'; +import { test } from 'node:test'; +import assert from 'node:assert'; + +test('do not leak promises', async () => { + const buf = new Uint8Array(1); + const readable = new ReadableStream({ + start(controller) { + controller.enqueue(buf); + controller.close(); + } + }); + + const [out1, out2] = readable.tee(); + const cloned = structuredClone(out2, { transfer: [out2] }); + + for await (const chunk of cloned) { + assert.deepStrictEqual(chunk, buf); + } + + for await (const chunk of out2) { + assert.deepStrictEqual(chunk, buf); + } + + for await (const chunk of out1) { + assert.deepStrictEqual(chunk, buf); + } +});