repositories / pi-ext
pi-ext
bugabingas pi extensions
owned by admin
test/snapshot-lint.test.ts
Rawimport { globSync, readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
import { snapshotViolations } from "./snapshot-lint.ts";
describe("snapshot policy", () => {
it("keeps every committed snapshot normalized", () => {
const files = globSync("**/*.snap").filter(
(file) => !file.includes("node_modules"),
);
const offenders = files.flatMap((file) => {
const violations = snapshotViolations(readFileSync(file, "utf8"));
return violations.length ? [`${file}: ${violations.join(", ")}`] : [];
});
expect(offenders).toEqual([]);
});
it("rejects machine paths, timestamps, IDs, and bundle content", () => {
expect(snapshotViolations('cwd: "/home/me/project"')).toContain(
"absolute path",
);
expect(snapshotViolations("ran at 2024-01-02T03:04:05Z")).toContain(
"ISO timestamp",
);
expect(
snapshotViolations("session 123e4567-e89b-12d3-a456-426614174000"),
).toContain("UUID");
expect(
snapshotViolations("import x from './board-runtime-ms4ttrio.js'"),
).toContain("bundle chunk reference");
expect(snapshotViolations(process.cwd())).toContain("absolute path");
});
it("accepts normalized rendered output", () => {
expect(
snapshotViolations("✓ accepted · selected a, b · 1 annotation"),
).toEqual([]);
});
});