aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/spawn-streaming-stdout.test.ts
blob: 88c028db3d876c53468984e59878732f79725e65 (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
import { it, test, expect } from "bun:test";
import { spawn } from "bun";
import { bunExe } from "./bunExe";

test("spawn can read from stdout multiple chunks", async () => {
  const proc = spawn({
    cmd: [bunExe(), import.meta.dir + "/spawn-streaming-stdout-repro.js"],
    stdout: "pipe",
    env: {
      BUN_DEBUG_QUIET_LOGS: 1,
    },
  });

  var counter = 0;
  for await (var chunk of proc.stdout) {
    expect(new TextDecoder().decode(chunk)).toBe("Wrote to stdout\n");
    counter++;

    if (counter > 3) break;
  }

  expect(counter).toBe(4);
  proc.kill();
  await proc.exited;
});