diff options
author | 2022-10-11 14:56:49 -0700 | |
---|---|---|
committer | 2022-10-11 14:56:49 -0700 | |
commit | 8702f965a250071ccfb5b2676652496881f15b60 (patch) | |
tree | cc2a321e7345a01d7f9a11ac60096595d2b28061 /test/bun.js/spawn.test.ts | |
parent | 888a685e26e035f7261aaa8727506ec4e9b80714 (diff) | |
download | bun-8702f965a250071ccfb5b2676652496881f15b60.tar.gz bun-8702f965a250071ccfb5b2676652496881f15b60.tar.zst bun-8702f965a250071ccfb5b2676652496881f15b60.zip |
Add test for Bun.file() for stdin and stdout
Diffstat (limited to '')
-rw-r--r-- | test/bun.js/spawn.test.ts | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/test/bun.js/spawn.test.ts b/test/bun.js/spawn.test.ts index f7426660f..e03de2662 100644 --- a/test/bun.js/spawn.test.ts +++ b/test/bun.js/spawn.test.ts @@ -1,9 +1,47 @@ -import { readableStreamToText, spawn } from "bun"; +import { readableStreamToText, spawn, write } from "bun"; import { describe, expect, it } from "bun:test"; +import { rmdirSync, unlinkSync, rmSync } from "node:fs"; describe("spawn", () => { const hugeString = "hello".repeat(10000).slice(); + it("Bun.file() works as stdout", async () => { + rmSync("/tmp/out.123.txt", { force: true }); + const { exited } = spawn({ + cmd: ["echo", "hello"], + stdout: Bun.file("/tmp/out.123.txt"), + }); + + await exited; + expect(await Bun.file("/tmp/out.123.txt").text()).toBe("hello\n"); + }); + + it("Bun.file() works as stdin", async () => { + await write(Bun.file("/tmp/out.456.txt"), "hello there!"); + const { stdout } = spawn({ + cmd: ["cat"], + stdout: "pipe", + stdin: Bun.file("/tmp/out.456.txt"), + }); + + expect(await readableStreamToText(stdout)).toBe("hello there!"); + }); + + it("Bun.file() works as stdin and stdout", async () => { + await write(Bun.file("/tmp/out.456.txt"), "hello!"); + await write(Bun.file("/tmp/out.123.txt"), "wrong!"); + + const { exited } = spawn({ + cmd: ["cat"], + stdout: Bun.file("/tmp/out.123.txt"), + stdin: Bun.file("/tmp/out.456.txt"), + }); + + await exited; + expect(await Bun.file("/tmp/out.456.txt").text()).toBe("hello!"); + expect(await Bun.file("/tmp/out.123.txt").text()).toBe("hello!"); + }); + it("stdout can be read", async () => { await Bun.write("/tmp/out.txt", hugeString); const { stdout } = spawn({ |