import { readFile } from "node:fs/promises"; import { describe, expect, it } from "vitest"; import { formatArchitectureViolation } from "../../scripts/lib/architecture-violation-message.ts"; // 12-11. A violation used to print only the rule name and the file pair; the // reason and the way out were in .dependency-cruiser.json. describe("architecture violation message", () => { it("names the import and says why and where to go", () => { expect( formatArchitectureViolation( { rule: "concrete-adapters-compose-only-in-bootstrap", source: "src/presentation/pages/probe.tsx", target: "src/adapters/http/index.ts", }, ["../../adapters/http/index.ts"], "Only src/bootstrap constructs concrete adapters.", ), ).toBe( "Architecture violation [concrete-adapters-compose-only-in-bootstrap]: " + "src/presentation/pages/probe.tsx -> src/adapters/http/index.ts " + '(import "../../adapters/http/index.ts")\n' + " why: Only src/bootstrap constructs concrete adapters.\n", ); }); it("gives every rule a reason to print", async () => { const config = JSON.parse(await readFile(".dependency-cruiser.json", "utf8")) as { forbidden: { name: string; comment?: string }[]; }; expect(config.forbidden.filter(({ comment }) => !comment?.trim()).map(({ name }) => name)).toEqual([]); }); });