74 lines
2.8 KiB
TypeScript
74 lines
2.8 KiB
TypeScript
import { existsSync, readdirSync, statSync } from "node:fs";
|
|
import { join, relative, resolve } from "node:path";
|
|
import { describe, expect, it } from "@suaveplan/testing/runner";
|
|
import pkg from "../package.json" with { type: "json" };
|
|
|
|
const ROOT = resolve(__dirname, "..");
|
|
const SRC = join(ROOT, "src");
|
|
|
|
function walk(dir: string, out: string[] = []): string[] {
|
|
for (const entry of readdirSync(dir)) {
|
|
const full = join(dir, entry);
|
|
const st = statSync(full);
|
|
if (st.isDirectory()) walk(full, out);
|
|
else out.push(full);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
describe("dep-graph", () => {
|
|
it("every impl .ts has a sibling .md", { timeout: 5000 }, () => {
|
|
const missing: string[] = [];
|
|
for (const f of walk(SRC)) {
|
|
if (!f.endsWith(".ts")) continue;
|
|
if (f.endsWith(".test.ts")) continue;
|
|
if (f.endsWith(".spec-conformance.test.ts")) continue;
|
|
if (f.endsWith(".types.ts")) continue;
|
|
if (f.endsWith("/index.ts")) continue;
|
|
const md = f.replace(/\.ts$/, ".md");
|
|
if (!existsSync(md)) missing.push(relative(ROOT, md));
|
|
}
|
|
expect(missing).toEqual([]);
|
|
});
|
|
|
|
it("every subpath export resolves to a real source file", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
const entries = pkg.exports as Record<string, unknown>;
|
|
const missing: string[] = [];
|
|
for (const [key, value] of Object.entries(entries)) {
|
|
if (key === "./package.json") continue;
|
|
const distPath =
|
|
typeof value === "object" && value !== null
|
|
? (
|
|
value as {
|
|
import?: { default?: string };
|
|
}
|
|
).import?.default
|
|
: (value as string);
|
|
if (typeof distPath !== "string") continue;
|
|
const srcPath = distPath
|
|
.replace(/^\.\/dist\//, "./src/")
|
|
.replace(/\.js$/, ".ts");
|
|
const abs = join(ROOT, srcPath);
|
|
if (!existsSync(abs)) missing.push(`${key} → ${srcPath}`);
|
|
}
|
|
expect(missing).toEqual([]);
|
|
});
|
|
|
|
it("runtime workspace dependencies are pinned", { timeout: 5000 }, () => {
|
|
const deps = Object.keys(pkg.dependencies ?? {}).sort();
|
|
expect(deps).toContain("@suaveplan/api-plugin");
|
|
expect(deps).toContain("@suaveplan/error");
|
|
expect(deps).toContain("@suaveplan/events");
|
|
expect(deps).toContain("@suaveplan/types");
|
|
const workspaceDeps = deps.filter((d) => d.startsWith("@suaveplan/"));
|
|
expect(workspaceDeps).toEqual([
|
|
"@suaveplan/api-plugin",
|
|
"@suaveplan/error",
|
|
"@suaveplan/events",
|
|
"@suaveplan/types",
|
|
]);
|
|
});
|
|
});
|