aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/spawn.test.ts
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-10-11 22:21:06 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-10-11 22:21:06 -0700
commite7eadcde5a17bd46dddba89b0baddc39d7ddb680 (patch)
treeab7c03d12341faf4736eeee037b39a2f3da17f68 /test/bun.js/spawn.test.ts
parent36adee4dc80c0aeb4d46bf56775af2a7a512b576 (diff)
downloadbun-e7eadcde5a17bd46dddba89b0baddc39d7ddb680.tar.gz
bun-e7eadcde5a17bd46dddba89b0baddc39d7ddb680.tar.zst
bun-e7eadcde5a17bd46dddba89b0baddc39d7ddb680.zip
Implement `Bun.spawnSync`
Diffstat (limited to 'test/bun.js/spawn.test.ts')
-rw-r--r--test/bun.js/spawn.test.ts42
1 files changed, 41 insertions, 1 deletions
diff --git a/test/bun.js/spawn.test.ts b/test/bun.js/spawn.test.ts
index b8e0459c5..6829791ce 100644
--- a/test/bun.js/spawn.test.ts
+++ b/test/bun.js/spawn.test.ts
@@ -1,4 +1,4 @@
-import { readableStreamToText, spawn, write } from "bun";
+import { readableStreamToText, spawn, spawnSync, write } from "bun";
import { describe, expect, it } from "bun:test";
import { gcTick as _gcTick } from "gc";
import { rmdirSync, unlinkSync, rmSync, writeFileSync } from "node:fs";
@@ -8,9 +8,49 @@ for (let [gcTick, label] of [
[() => {}, "no gc tick"],
]) {
describe(label, () => {
+ describe("spawnSync", () => {
+ const hugeString = "hello".repeat(10000).slice();
+
+ it("Uint8Array works as stdin", async () => {
+ const { stdout, stderr } = spawnSync({
+ cmd: ["cat"],
+ stdin: new TextEncoder().encode(hugeString),
+ });
+
+ expect(stdout.toString()).toBe(hugeString);
+ expect(stderr.byteLength).toBe(0);
+ });
+ });
+
describe("spawn", () => {
const hugeString = "hello".repeat(10000).slice();
+ it("Uint8Array works as stdin", async () => {
+ rmSync("/tmp/out.123.txt", { force: true });
+ gcTick();
+ const { exited } = spawn({
+ cmd: ["cat"],
+ stdin: new TextEncoder().encode(hugeString),
+ stdout: Bun.file("/tmp/out.123.txt"),
+ });
+
+ await exited;
+ expect(await Bun.file("/tmp/out.123.txt").text()).toBe(hugeString);
+ });
+
+ it("Blob works as stdin", async () => {
+ rmSync("/tmp/out.123.txt", { force: true });
+ gcTick();
+ const { exited } = spawn({
+ cmd: ["cat"],
+ stdin: new Blob([new TextEncoder().encode(hugeString)]),
+ stdout: Bun.file("/tmp/out.123.txt"),
+ });
+
+ await exited;
+ expect(await Bun.file("/tmp/out.123.txt").text()).toBe(hugeString);
+ });
+
it("Bun.file() works as stdout", async () => {
rmSync("/tmp/out.123.txt", { force: true });
gcTick();