// Tests for util.ts // Pure unit tests with filesystem import assert from "node:assert/strict"; import { mkdir, rm, writeFile } from "node:fs/promises"; import { join } from "node:path"; import { after, before, describe, it } from "node:test"; import { loadFile } from "./util"; describe("util", () => { const testDir = join(import.meta.dirname, ".test-util-tmp"); before(async () => { await mkdir(testDir, { recursive: true }); }); after(async () => { await rm(testDir, { recursive: true, force: true }); }); describe("loadFile", () => { it("loads file contents as string", async () => { const testFile = join(testDir, "test.txt"); await writeFile(testFile, "hello world"); const content = await loadFile(testFile); assert.equal(content, "hello world"); }); it("handles utf-8 content", async () => { const testFile = join(testDir, "utf8.txt"); await writeFile(testFile, "hello \u{1F511} world"); const content = await loadFile(testFile); assert.equal(content, "hello \u{1F511} world"); }); it("handles empty file", async () => { const testFile = join(testDir, "empty.txt"); await writeFile(testFile, ""); const content = await loadFile(testFile); assert.equal(content, ""); }); it("handles multiline content", async () => { const testFile = join(testDir, "multiline.txt"); await writeFile(testFile, "line1\nline2\nline3"); const content = await loadFile(testFile); assert.equal(content, "line1\nline2\nline3"); }); it("throws for nonexistent file", async () => { await assert.rejects( loadFile(join(testDir, "nonexistent.txt")), /ENOENT/, ); }); }); });