diff options
author | 2022-11-25 00:08:36 -0800 | |
---|---|---|
committer | 2022-11-25 00:08:36 -0800 | |
commit | d1a4f4fd6981a06920adb632dde2562b76ddc4d0 (patch) | |
tree | 6a26cd3ebd8afdbad653a800d54967c4e84b55c2 /test/bun.js/spawn-streaming-stdin.test.ts | |
parent | 0b915fed034c38ae9a2e15caee94530910dc864b (diff) | |
download | bun-d1a4f4fd6981a06920adb632dde2562b76ddc4d0.tar.gz bun-d1a4f4fd6981a06920adb632dde2562b76ddc4d0.tar.zst bun-d1a4f4fd6981a06920adb632dde2562b76ddc4d0.zip |
Introduce `FileSink.ref()` and `FileSink.unref()`
Diffstat (limited to 'test/bun.js/spawn-streaming-stdin.test.ts')
-rw-r--r-- | test/bun.js/spawn-streaming-stdin.test.ts | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/test/bun.js/spawn-streaming-stdin.test.ts b/test/bun.js/spawn-streaming-stdin.test.ts index 953548071..6424eadfc 100644 --- a/test/bun.js/spawn-streaming-stdin.test.ts +++ b/test/bun.js/spawn-streaming-stdin.test.ts @@ -12,30 +12,40 @@ test("spawn can write to stdin multiple chunks", async () => { cmd: [bunExe(), import.meta.dir + "/stdin-repro.js"], stdout: "pipe", stdin: "pipe", - stderr: "inherit", + stderr: Bun.file("/tmp/out.log"), env: { BUN_DEBUG_QUIET_LOGS: 1, }, }); + // (async function () { + // for await (var chunk of proc.stderr) { + // console.error("[stderr]", new TextDecoder().decode(chunk)); + // } + // })(); exited = proc.exited; var counter = 0; var inCounter = 0; const prom2 = (async function () { - while (inCounter++ < 4) { + while (true) { await new Promise((resolve, reject) => setTimeout(resolve, 8)); proc.stdin.write("Wrote to stdin!"); - await proc.stdin.flush(); + inCounter++; + + if (inCounter === 4) break; } - await proc.stdin.end(); + await new Promise((resolve) => + Promise.resolve(proc.stdin.end()).then(resolve), + ); })(); + var chunks = []; const prom = (async function () { try { for await (var chunk of proc.stdout) { - expect(new TextDecoder().decode(chunk)).toBe("Wrote to stdin!\n"); + chunks.push(chunk); counter++; - if (counter > 3) break; + if (counter === 4) break; } } catch (e) { console.log(e.stack); @@ -43,11 +53,15 @@ test("spawn can write to stdin multiple chunks", async () => { } })(); await Promise.all([prom, prom2]); + const code = await exited; + console.log(code); expect(counter).toBe(4); + expect(Buffer.concat(chunks).toString().trim()).toBe( + "Wrote to stdin!\n".repeat(4).trim(), + ); // proc.kill(); + + gcTick(true); })(); - await exited; } - - gcTick(true); }); |