From 74069add3f400ad6b232ad18840206ab96b9fe80 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 16 Sep 2024 14:23:40 +0200 Subject: fix(runtime): don't error `child.output()` on consumed stream (#25657) This fixes the fast path for `readableStreamCollectIntoUint8Array` to only trigger if the readable stream has not yet been disturbed - because otherwise we may not be able to close it if the read errors. --- tests/unit/command_test.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests') diff --git a/tests/unit/command_test.ts b/tests/unit/command_test.ts index 523d20cf3..51bbdd860 100644 --- a/tests/unit/command_test.ts +++ b/tests/unit/command_test.ts @@ -1043,3 +1043,24 @@ Deno.test( } }, ); + +Deno.test(async function outputWhenManuallyConsumingStreams() { + const command = new Deno.Command(Deno.execPath(), { + args: ["eval", "console.log('hello world')"], + stdout: "piped", + stderr: "piped", + }); + const child = command.spawn(); + for await (const _ of child.stdout) { + // consume stdout + } + for await (const _ of child.stderr) { + // consume stderr + } + const status = await child.output(); + assertEquals(status.success, true); + assertEquals(status.code, 0); + assertEquals(status.signal, null); + assertEquals(status.stdout, new Uint8Array()); + assertEquals(status.stderr, new Uint8Array()); +}); -- cgit v1.2.3