aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/spawn-streaming-stdin.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'test/bun.js/spawn-streaming-stdin.test.ts')
-rw-r--r--test/bun.js/spawn-streaming-stdin.test.ts53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/bun.js/spawn-streaming-stdin.test.ts b/test/bun.js/spawn-streaming-stdin.test.ts
new file mode 100644
index 000000000..953548071
--- /dev/null
+++ b/test/bun.js/spawn-streaming-stdin.test.ts
@@ -0,0 +1,53 @@
+import { it, test, expect } from "bun:test";
+import { spawn } from "bun";
+import { bunExe } from "./bunExe";
+import { gcTick } from "gc";
+
+const N = 100;
+test("spawn can write to stdin multiple chunks", async () => {
+ for (let i = 0; i < N; i++) {
+ var exited;
+ await (async function () {
+ const proc = spawn({
+ cmd: [bunExe(), import.meta.dir + "/stdin-repro.js"],
+ stdout: "pipe",
+ stdin: "pipe",
+ stderr: "inherit",
+ env: {
+ BUN_DEBUG_QUIET_LOGS: 1,
+ },
+ });
+ exited = proc.exited;
+ var counter = 0;
+ var inCounter = 0;
+ const prom2 = (async function () {
+ while (inCounter++ < 4) {
+ await new Promise((resolve, reject) => setTimeout(resolve, 8));
+ proc.stdin.write("Wrote to stdin!");
+ await proc.stdin.flush();
+ }
+ await proc.stdin.end();
+ })();
+
+ const prom = (async function () {
+ try {
+ for await (var chunk of proc.stdout) {
+ expect(new TextDecoder().decode(chunk)).toBe("Wrote to stdin!\n");
+ counter++;
+
+ if (counter > 3) break;
+ }
+ } catch (e) {
+ console.log(e.stack);
+ throw e;
+ }
+ })();
+ await Promise.all([prom, prom2]);
+ expect(counter).toBe(4);
+ // proc.kill();
+ })();
+ await exited;
+ }
+
+ gcTick(true);
+});