Files
bun.sh/test/js/bun/util/bun-file-exists.test.js
2024-09-03 21:32:52 -07:00

21 lines
787 B
JavaScript

import { write } from "bun";
import { expect, test } from "bun:test";
import { unlinkSync } from "fs";
import { tmpdir } from "os";
import { join } from "path";
test("bun-file-exists", async () => {
expect(await Bun.file(import.meta.path).exists()).toBeTrue();
expect(await Bun.file(import.meta.path + "boop").exists()).toBeFalse();
expect(await Bun.file(import.meta.dir).exists()).toBeFalse();
expect(await Bun.file(import.meta.dir + "/").exists()).toBeFalse();
const temp = join(tmpdir(), "bun-file-exists.test.js");
try {
unlinkSync(temp);
} catch (e) {}
expect(await Bun.file(temp).exists()).toBeFalse();
await write(temp, "boop");
expect(await Bun.file(temp).exists()).toBeTrue();
unlinkSync(temp);
expect(await Bun.file(temp).exists()).toBeFalse();
});