From f052e66df538f7fabb0e173d9dd79888201286f2 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Sun, 4 Dec 2022 02:53:04 -0800 Subject: Add some basic tests for process.stdout --- test/bun.js/process-stdio.test.ts | 69 ++++++++++++++++++++++++++++++++ test/bun.js/stdio-test-instance-a-lot.js | 23 +++++++++++ test/bun.js/stdio-test-instance.js | 9 +++++ 3 files changed, 101 insertions(+) create mode 100644 test/bun.js/process-stdio.test.ts create mode 100644 test/bun.js/stdio-test-instance-a-lot.js create mode 100644 test/bun.js/stdio-test-instance.js (limited to 'test/bun.js') diff --git a/test/bun.js/process-stdio.test.ts b/test/bun.js/process-stdio.test.ts new file mode 100644 index 000000000..886bf9dac --- /dev/null +++ b/test/bun.js/process-stdio.test.ts @@ -0,0 +1,69 @@ +import { spawnSync } from "bun"; +import { describe, expect, it, test } from "bun:test"; +import { bunExe } from "bunExe"; +import { isatty } from "tty"; + +test("process.stdout", () => { + expect(process.stdout).toBeDefined(); + expect(process.stdout.isTTY).toBe(isatty(1)); +}); + +test("process.stderr", () => { + expect(process.stderr).toBeDefined(); + expect(process.stderr.isTTY).toBe(isatty(2)); +}); + +test("process.stdout - write", () => { + const { stdout } = spawnSync({ + cmd: [bunExe(), import.meta.dir + "/stdio-test-instance.js"], + stdout: "pipe", + stdin: null, + stderr: null, + env: { + ...process.env, + BUN_DEBUG_QUIET_LOGS: "1", + }, + }); + + expect(stdout?.toString()).toBe( + `hello worldhello again|😋 Get Emoji — All Emojis to ✂️ Copy and 📋 Paste 👌`, + ); +}); + +test("process.stdout - write a lot (string)", () => { + const { stdout } = spawnSync({ + cmd: [bunExe(), import.meta.dir + "/stdio-test-instance-a-lot.js"], + stdout: "pipe", + stdin: null, + stderr: null, + env: { + ...process.env, + BUN_DEBUG_QUIET_LOGS: "1", + TEST_STDIO_STRING: "1", + }, + }); + + expect(stdout?.toString()).toBe( + `hello worldhello again|😋 Get Emoji — All Emojis to ✂️ Copy and 📋 Paste 👌`.repeat( + 9999, + ), + ); +}); + +test("process.stdout - write a lot (bytes)", () => { + const { stdout } = spawnSync({ + cmd: [bunExe(), import.meta.dir + "/stdio-test-instance-a-lot.js"], + stdout: "pipe", + stdin: null, + stderr: null, + env: { + ...process.env, + BUN_DEBUG_QUIET_LOGS: "1", + }, + }); + expect(stdout?.toString()).toBe( + `hello worldhello again|😋 Get Emoji — All Emojis to ✂️ Copy and 📋 Paste 👌`.repeat( + 9999, + ), + ); +}); diff --git a/test/bun.js/stdio-test-instance-a-lot.js b/test/bun.js/stdio-test-instance-a-lot.js new file mode 100644 index 000000000..2b65d786c --- /dev/null +++ b/test/bun.js/stdio-test-instance-a-lot.js @@ -0,0 +1,23 @@ +import { ArrayBufferSink } from "bun"; + +const sink = new ArrayBufferSink(); + +sink.write("hello"); +sink.write(" "); +sink.write("world"); +sink.write(new TextEncoder().encode("hello again|")); +sink.write( + new TextEncoder().encode( + "😋 Get Emoji — All Emojis to ✂️ Copy and 📋 Paste 👌", + ), +); + +const string = Buffer.from(sink.end()).toString().repeat(9999); + +if (process.env.TEST_STDIO_STRING) { + const result = string; + process.stdout.write(result); +} else { + const result = Buffer.from(string); + process.stdout.write(result); +} diff --git a/test/bun.js/stdio-test-instance.js b/test/bun.js/stdio-test-instance.js new file mode 100644 index 000000000..36e48f472 --- /dev/null +++ b/test/bun.js/stdio-test-instance.js @@ -0,0 +1,9 @@ +process.stdout.write("hello"); +process.stdout.write(" "); +process.stdout.write("world"); +process.stdout.write(new TextEncoder().encode("hello again|")); +process.stdout.write( + new TextEncoder().encode( + "😋 Get Emoji — All Emojis to ✂️ Copy and 📋 Paste 👌", + ), +); -- cgit v1.2.3