diff options
| author | 2022-11-23 07:14:33 -0800 | |
|---|---|---|
| committer | 2022-11-23 07:14:33 -0800 | |
| commit | ac36ea51cfb85130403ac09299f8e1207bad4bcb (patch) | |
| tree | a05bc2d34295bc0087b68b799155f18050451721 /test/bun.js/spawn-streaming-stdout.test.ts | |
| parent | ae3fcb5bd89a4ac908ba6d4cdb1be4e7c7f0ea81 (diff) | |
| download | bun-ac36ea51cfb85130403ac09299f8e1207bad4bcb.tar.gz bun-ac36ea51cfb85130403ac09299f8e1207bad4bcb.tar.zst bun-ac36ea51cfb85130403ac09299f8e1207bad4bcb.zip | |
possibly more reliable Bun.spawn (#1547)
* wip
* wip
* Fix bug with stdin
* zig fmt
* seems to work!
* Update streams.test.js
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to '')
| -rw-r--r-- | test/bun.js/spawn-streaming-stdout.test.ts | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/test/bun.js/spawn-streaming-stdout.test.ts b/test/bun.js/spawn-streaming-stdout.test.ts index 88c028db3..1f736533a 100644 --- a/test/bun.js/spawn-streaming-stdout.test.ts +++ b/test/bun.js/spawn-streaming-stdout.test.ts @@ -1,25 +1,41 @@ import { it, test, expect } from "bun:test"; import { spawn } from "bun"; import { bunExe } from "./bunExe"; +import { gcTick } from "gc"; 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, - }, - }); + gcTick(true); + var exited; + await (async function () { + const proc = spawn({ + cmd: [bunExe(), import.meta.dir + "/spawn-streaming-stdout-repro.js"], + stdout: "pipe", + env: { + BUN_DEBUG_QUIET_LOGS: 1, + }, + }); + exited = proc.exited; + gcTick(true); + var counter = 0; + try { + for await (var chunk of proc.stdout) { + gcTick(true); + expect(new TextDecoder().decode(chunk)).toBe("Wrote to stdout\n"); + counter++; - 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; + } + } catch (e) { + console.log(e.stack); + throw e; + } + gcTick(true); - if (counter > 3) break; - } - - expect(counter).toBe(4); - proc.kill(); - await proc.exited; + expect(counter).toBe(4); + gcTick(); + proc.kill(); + gcTick(); + })(); + await exited; + gcTick(true); }); |
