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); + } +});