From e096a03e3e7463e63d2338730e2387ddf6733f6c Mon Sep 17 00:00:00 2001 From: Ciro Spaciari Date: Sun, 14 May 2023 14:22:02 -0300 Subject: fix(spawn) add Uint8Array support for stdout (#2866) * add array_buffer support for stdout * fix comment * fix param name on baby_list * keep test names consistent * add more test cases --- test/js/bun/spawn/spawn.test.ts | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'test/js') diff --git a/test/js/bun/spawn/spawn.test.ts b/test/js/bun/spawn/spawn.test.ts index c43c06d02..753bcda6a 100644 --- a/test/js/bun/spawn/spawn.test.ts +++ b/test/js/bun/spawn/spawn.test.ts @@ -162,6 +162,70 @@ for (let [gcTick, label] of [ } }); + it("Uint8Array works as stdout", () => { + gcTick(); + const stdout_buffer = new Uint8Array(11); + const { stdout } = spawnSync(["echo", "hello world"], { + stdout: stdout_buffer, + stderr: null, + stdin: null, + }); + gcTick(); + const text = new TextDecoder().decode(stdout); + const text2 = new TextDecoder().decode(stdout_buffer); + expect(text).toBe("hello world"); + expect(text2).toBe("hello world"); + gcTick(); + }); + + it("Uint8Array works as stdout when is smaller than output", () => { + gcTick(); + const stdout_buffer = new Uint8Array(5); + const { stdout } = spawnSync(["echo", "hello world"], { + stdout: stdout_buffer, + stderr: null, + stdin: null, + }); + gcTick(); + const text = new TextDecoder().decode(stdout); + const text2 = new TextDecoder().decode(stdout_buffer); + expect(text).toBe("hello"); + expect(text2).toBe("hello"); + gcTick(); + }); + + it("Uint8Array works as stdout when is the exactly size than output", () => { + gcTick(); + const stdout_buffer = new Uint8Array(12); + const { stdout } = spawnSync(["echo", "hello world"], { + stdout: stdout_buffer, + stderr: null, + stdin: null, + }); + gcTick(); + const text = new TextDecoder().decode(stdout); + const text2 = new TextDecoder().decode(stdout_buffer); + expect(text).toBe("hello world\n"); + expect(text2).toBe("hello world\n"); + gcTick(); + }); + + it("Uint8Array works as stdout when is larger than output", () => { + gcTick(); + const stdout_buffer = new Uint8Array(15); + const { stdout } = spawnSync(["echo", "hello world"], { + stdout: stdout_buffer, + stderr: null, + stdin: null, + }); + gcTick(); + const text = new TextDecoder().decode(stdout); + const text2 = new TextDecoder().decode(stdout_buffer); + expect(text).toBe("hello world\n"); + expect(text2).toBe("hello world\n\u0000\u0000\u0000"); + gcTick(); + }); + it("Blob works as stdin", async () => { rmSync("/tmp/out.123.txt", { force: true }); gcTick(); -- cgit v1.2.3