Files
bun.sh/test/js/bun/shell/lazy.test.ts
2024-09-03 21:32:52 -07:00

20 lines
634 B
TypeScript

import { $ } from "bun";
import { expect, test } from "bun:test";
import { tempDirWithFiles } from "harness";
import { rmSync } from "node:fs";
import { join } from "path";
test("$ is lazy", async () => {
const base = tempDirWithFiles("bun-lazy-test", {
"bun-lazy": "789",
});
const path = join(base, "bun-lazy");
rmSync(path, { force: true, recursive: true });
const pending = $`echo 123 > ${path}`;
expect(async () => await Bun.file(path).text()).toThrow();
await Bun.write(path, "456");
expect(await Bun.file(path).text()).toBe("456");
await pending;
expect(await Bun.file(path).text()).toBe("123\n");
});