Files
suaveplan/packages/api-stack/api/api-tenant-resolver-header/tests/dep-graph.test.ts
2026-05-27 23:29:53 +01:00

70 lines
2.2 KiB
TypeScript

import { readdirSync, readFileSync, statSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "@suaveplan/testing/runner";
const PKG = join(__dirname, "..", "package.json");
const SRC = join(__dirname, "..", "src");
describe("@suaveplan/api-tenant-resolver-header package shape", () => {
it("depends on the expected set of workspace + catalog packages", {
timeout: 5000,
}, () => {
const pkg = JSON.parse(readFileSync(PKG, "utf8")) as {
dependencies: Record<string, string>;
};
const deps = Object.keys(pkg.dependencies).sort();
expect(deps).toEqual([
"@opentelemetry/api",
"@suaveplan/api-types",
"@suaveplan/error",
"tslib",
"zod",
]);
});
it("every src file uses default-import z (no named import)", {
timeout: 5000,
}, () => {
const offenders: string[] = [];
walk(SRC, (file) => {
if (!file.endsWith(".ts")) return;
const content = readFileSync(file, "utf8");
if (/import\s*\{\s*z\s*\}\s*from\s*["']zod["']/.test(content)) {
offenders.push(file);
}
});
expect(offenders).toEqual([]);
});
it("root barrel has no export-star", { timeout: 5000 }, () => {
const content = readFileSync(join(SRC, "index.ts"), "utf8");
expect(/export\s*\*/.test(content)).toBe(false);
});
it("no test file imports vitest / bun:test directly (rule 11)", {
timeout: 5000,
}, () => {
const offenders: string[] = [];
walk(SRC, (file) => {
if (!file.endsWith(".test.ts")) return;
const content = readFileSync(file, "utf8");
if (
/from\s*["'](?:vitest|bun:test)["']/.test(content) &&
!/from\s*["']vitest\/config["']/.test(content)
) {
offenders.push(file);
}
});
expect(offenders).toEqual([]);
});
});
function walk(dir: string, fn: (file: string) => void): void {
for (const name of readdirSync(dir)) {
const p = join(dir, name);
const st = statSync(p);
if (st.isDirectory()) walk(p, fn);
else fn(p);
}
}