aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Ciro Spaciari <ciro.spaciari@gmail.com> 2023-05-14 14:22:02 -0300
committerGravatar GitHub <noreply@github.com> 2023-05-14 10:22:02 -0700
commite096a03e3e7463e63d2338730e2387ddf6733f6c (patch)
tree08535f819efc9c2ac2d8a67abd8ea0d658c43489 /test
parentbf9e40d5b49f1ed16ea9abed4e231456dcda99c0 (diff)
downloadbun-e096a03e3e7463e63d2338730e2387ddf6733f6c.tar.gz
bun-e096a03e3e7463e63d2338730e2387ddf6733f6c.tar.zst
bun-e096a03e3e7463e63d2338730e2387ddf6733f6c.zip
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
Diffstat (limited to 'test')
-rw-r--r--test/js/bun/spawn/spawn.test.ts64
1 files changed, 64 insertions, 0 deletions
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();