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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
import { spawn, spawnSync } from "bun";
import { describe, expect, it, test } from "bun:test";
import { bunExe } from "harness";
import { isatty } from "tty";
test("process.stdin", () => {
expect(process.stdin).toBeDefined();
expect(process.stdout.isTTY).toBe(isatty(0));
expect(process.stdin.on("close", function () {})).toBe(process.stdin);
expect(process.stdin.once("end", function () {})).toBe(process.stdin);
});
test("process.stdin - read", async () => {
const { stdin, stdout } = spawn({
cmd: [bunExe(), import.meta.dir + "/process-stdin-echo.js"],
stdout: "pipe",
stdin: "pipe",
stderr: null,
env: {
...process.env,
BUN_DEBUG_QUIET_LOGS: "1",
},
});
expect(stdin).toBeDefined();
expect(stdout).toBeDefined();
var lines = ["Get Emoji", "— All Emojis to ✂️ Copy and 📋 Paste", "👌", ""];
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
setTimeout(() => {
if (line) {
stdin?.write(line + "\n");
stdin?.flush();
} else {
stdin?.end();
}
}, i * 200);
}
var text = await new Response(stdout).text();
expect(text).toBe(lines.join("\n") + "ENDED");
});
test("process.stdin - resume", async () => {
const { stdin, stdout } = spawn({
cmd: [bunExe(), import.meta.dir + "/process-stdin-echo.js", "resume"],
stdout: "pipe",
stdin: "pipe",
stderr: null,
env: {
...process.env,
BUN_DEBUG_QUIET_LOGS: "1",
},
});
expect(stdin).toBeDefined();
expect(stdout).toBeDefined();
var lines = ["Get Emoji", "— All Emojis to ✂️ Copy and 📋 Paste", "👌", ""];
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
setTimeout(() => {
if (line) {
stdin?.write(line + "\n");
stdin?.flush();
} else {
stdin?.end();
}
}, i * 200);
}
var text = await new Response(stdout).text();
expect(text).toBe("RESUMED" + lines.join("\n") + "ENDED");
});
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),
);
});
|