Files
clean-architecture-frontend…/tests/unit/architecture-violation-message.test.ts
T
DongHyeonkaandClaude Opus 5.5 b0f7944b41 fix(architecture): print why an import is forbidden and where to go (12-11)
Graph violations printed only the rule name and file pair, and ESLint only the
pattern. The graph now prints the import specifier and the rule's comment,
every rule has one, and ESLint pattern groups carry a message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 22:49:32 +09:00

36 lines
1.4 KiB
TypeScript

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([]);
});
});