aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--test/bun.js/spawn-streaming-stdin.test.ts39
-rw-r--r--test/bun.js/stdin-repro.js11
2 files changed, 21 insertions, 29 deletions
diff --git a/test/bun.js/spawn-streaming-stdin.test.ts b/test/bun.js/spawn-streaming-stdin.test.ts
index 6424eadfc..2285c50d2 100644
--- a/test/bun.js/spawn-streaming-stdin.test.ts
+++ b/test/bun.js/spawn-streaming-stdin.test.ts
@@ -9,7 +9,7 @@ test("spawn can write to stdin multiple chunks", async () => {
var exited;
await (async function () {
const proc = spawn({
- cmd: [bunExe(), import.meta.dir + "/stdin-repro.js"],
+ cmd: ["bun-debug", import.meta.dir + "/stdin-repro.js"],
stdout: "pipe",
stdin: "pipe",
stderr: Bun.file("/tmp/out.log"),
@@ -17,51 +17,40 @@ test("spawn can write to stdin multiple chunks", async () => {
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 (true) {
- await new Promise((resolve, reject) => setTimeout(resolve, 8));
- proc.stdin.write("Wrote to stdin!");
- inCounter++;
-
- if (inCounter === 4) break;
- }
- 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) {
chunks.push(chunk);
- counter++;
-
- if (counter === 4) break;
}
} catch (e) {
console.log(e.stack);
throw e;
}
})();
+
+ const prom2 = (async function () {
+ while (true) {
+ proc.stdin.write("Wrote to stdin!\n");
+ inCounter++;
+ await new Promise((resolve) => setTimeout(resolve, 8));
+
+ if (inCounter === 4) break;
+ }
+ proc.stdin.end();
+ })();
+
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 1;
})();
}
});
diff --git a/test/bun.js/stdin-repro.js b/test/bun.js/stdin-repro.js
index 5f945be7c..02840d00b 100644
--- a/test/bun.js/stdin-repro.js
+++ b/test/bun.js/stdin-repro.js
@@ -1,7 +1,10 @@
-var count = 5;
+var stdout = Bun.stdout.writer();
+console.error("Started");
+var count = 0;
for await (let chunk of Bun.stdin.stream()) {
const str = new Buffer(chunk).toString();
- console.error("how many?", count, chunk.byteLength);
- count -= str.split("\n").length;
- console.log(str);
+ stdout.write(str);
+ stdout.flush();
+ count++;
}
+console.error("Finished with", count);