aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/process-stdio.test.ts
blob: 45db37d050c209f9b0d52f004bad060dfbf4d254 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { spawnSync } from "bun";
import { describe, expect, it, test } from "bun:test";
import { bunExe } from "bunExe";
import { isatty } from "tty";

test("process.stdin", () => {
  expect(process.stdin).toBeDefined();
  expect(process.stdin.on("close", function() {})).toBe(process.stdin);
  expect(process.stdin.once("end", function() {})).toBe(process.stdin);
});

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