aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js
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
parent36adee4dc80c0aeb4d46bf56775af2a7a512b576 (diff)
downloadbun-e7eadcde5a17bd46dddba89b0baddc39d7ddb680.tar.gz
bun-e7eadcde5a17bd46dddba89b0baddc39d7ddb680.tar.zst
bun-e7eadcde5a17bd46dddba89b0baddc39d7ddb680.zip
Implement `Bun.spawnSync`
Diffstat (limited to '')
-rw-r--r--test/bun.js/log-test.test.ts20
-rw-r--r--test/bun.js/spawn.test.ts42
2 files changed, 46 insertions, 16 deletions
diff --git a/test/bun.js/log-test.test.ts b/test/bun.js/log-test.test.ts
index ecc2c3939..bdb6cbe42 100644
--- a/test/bun.js/log-test.test.ts
+++ b/test/bun.js/log-test.test.ts
@@ -1,7 +1,7 @@
import { it, expect } from "bun:test";
import { basename, dirname, join } from "path";
import * as fs from "fs";
-import { readableStreamToText, spawn } from "bun";
+import { readableStreamToText, spawnSync } from "bun";
it("should not log .env when quiet", async () => {
writeDirectoryTree("/tmp/log-test-silent", {
@@ -9,17 +9,12 @@ it("should not log .env when quiet", async () => {
"bunfig.toml": `logLevel = "error"`,
"index.ts": "export default console.log('Here');",
});
- const out = spawn({
+ const { stderr } = spawnSync({
cmd: ["bun", "index.ts"],
- stdout: "pipe",
- stderr: "pipe",
cwd: "/tmp/log-test-silent",
});
- out.ref();
- await out.exited;
- const text = await readableStreamToText(out.stderr);
- expect(text).toBe("");
+ expect(stderr.toString()).toBe("");
});
it("should log .env by default", async () => {
@@ -29,17 +24,12 @@ it("should log .env by default", async () => {
"index.ts": "export default console.log('Here');",
});
- const out = spawn({
+ const { stderr } = spawnSync({
cmd: ["bun", "index.ts"],
- stdout: "pipe",
- stderr: "pipe",
cwd: "/tmp/log-test-silent",
});
- out.ref();
- await out.exited;
- const text = await readableStreamToText(out.stderr);
- expect(text.includes(".env")).toBe(true);
+ expect(stderr.toString().includes(".env")).toBe(true);
});
function writeDirectoryTree(base, paths) {
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();