import { describe, expect, it } from "vitest"; import { bytesEqual, createStepLog, dirOf } from "./selfTestSteps"; describe("createStepLog", () => { it("records passes, expectation failures and throws without throwing itself", async () => { let t = 0; const log = createStepLog(() => (t += 10)); await log.run("a", async () => "fine"); await log.run("b", async () => ({ ok: false, detail: "wrong" })); await log.run("c", async () => { throw new Error("boom"); }); expect(log.steps).toEqual([ { name: "a", ok: true, ms: 10, detail: "fine" }, { name: "b", ok: false, ms: 10, detail: "wrong" }, { name: "c", ok: false, ms: 10, detail: "Error: boom" }, ]); }); }); describe("dirOf / bytesEqual", () => { it("splits posix and windows paths", () => { expect(dirOf("/tmp/x/report.json")).toBe("/tmp/x"); expect(dirOf("C:\\out\\report.json")).toBe("C:\\out"); expect(dirOf("/report.json")).toBe("/"); expect(dirOf("report.json")).toBe(""); }); it("compares bytes", () => { expect(bytesEqual(new Uint8Array([1, 2]), new Uint8Array([1, 2]))).toBe(true); expect(bytesEqual(new Uint8Array([1, 2]), new Uint8Array([1, 3]))).toBe(false); expect(bytesEqual(new Uint8Array([1]), new Uint8Array([1, 2]))).toBe(false); }); });