import { describe, test, expect } from "vitest"; import { generatePostSynthBarrel, type BarrelEntry } from "./generate-post-synth-barrel"; describe("generatePostSynthBarrel", () => { test("emits a DO NOT EDIT banner, static imports, and an id-sorted array", () => { const entries: BarrelEntry[] = [ { module: "./gha021", exportName: "gha021", id: "GHA021" }, { module: "./apt-no-recommends", exportName: "dkrd010", id: "DKRD010" }, { module: "./gha006", exportName: "gha006", id: "GHA006" }, ]; const out = generatePostSynthBarrel(entries); expect(out).toContain("// Code generated by chant generate. DO NOT EDIT."); expect(out).toContain('import type { PostSynthCheck } from "@intentius/chant/lint/post-synth";'); // Export name may differ from the module name (docker/helm/temporal). expect(out).toContain('import { dkrd010 } from "./apt-no-recommends";'); // Array is ordered by id, not insertion order. const arrayBody = out.slice(out.indexOf("postSynthChecks: PostSynthCheck[] = [")); expect(arrayBody.indexOf("dkrd010")).toBeLessThan(arrayBody.indexOf("gha006")); expect(arrayBody.indexOf("gha006")).toBeLessThan(arrayBody.indexOf("gha021")); }); test("is deterministic regardless of input order", () => { const a: BarrelEntry[] = [ { module: "./b", exportName: "b", id: "X2" }, { module: "./a", exportName: "a", id: "X1" }, ]; const b = [...a].reverse(); expect(generatePostSynthBarrel(a)).toBe(generatePostSynthBarrel(b)); }); test("empty input yields an empty array, still valid", () => { const out = generatePostSynthBarrel([]); expect(out).toContain("export const postSynthChecks: PostSynthCheck[] = ["); expect(out).toContain("];"); }); });