75 lines
2.5 KiB
TypeScript
75 lines
2.5 KiB
TypeScript
import { readdir, readFile, stat } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it } from "@suaveplan/testing/runner";
|
|
|
|
const PKG_ROOT = join(__dirname, "..");
|
|
const SRC = join(PKG_ROOT, "src");
|
|
|
|
async function walk(dir: string): Promise<string[]> {
|
|
const out: string[] = [];
|
|
for (const entry of await readdir(dir)) {
|
|
const full = join(dir, entry);
|
|
const s = await stat(full);
|
|
if (s.isDirectory()) {
|
|
out.push(...(await walk(full)));
|
|
} else {
|
|
out.push(full);
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
|
|
describe("dep-graph", () => {
|
|
it("each adapter has its own subpath", { timeout: 5000 }, async () => {
|
|
const pkg = JSON.parse(
|
|
await readFile(join(PKG_ROOT, "package.json"), "utf8")
|
|
) as { exports: Record<string, unknown> };
|
|
const exportKeys = Object.keys(pkg.exports);
|
|
expect(exportKeys).toContain("./adapters/surrealql/surrealql");
|
|
expect(exportKeys).toContain("./adapters/postgres/postgres");
|
|
expect(exportKeys).toContain("./adapters/sqlite/sqlite");
|
|
});
|
|
|
|
it("subpath exports cover every feature module", {
|
|
timeout: 5000,
|
|
}, async () => {
|
|
const pkg = JSON.parse(
|
|
await readFile(join(PKG_ROOT, "package.json"), "utf8")
|
|
) as { exports: Record<string, unknown> };
|
|
const expected = [
|
|
".",
|
|
"./runner/runner",
|
|
"./adapters/surrealql/surrealql",
|
|
"./adapters/postgres/postgres",
|
|
"./adapters/sqlite/sqlite",
|
|
"./otel/instruments",
|
|
"./error-codes/error-codes",
|
|
"./types/migration",
|
|
];
|
|
for (const key of expected) {
|
|
expect(Object.keys(pkg.exports)).toContain(key);
|
|
}
|
|
});
|
|
|
|
it("every impl .ts has a sibling .md", { timeout: 5000 }, async () => {
|
|
const files = await walk(SRC);
|
|
const missing: string[] = [];
|
|
for (const file of files) {
|
|
if (!file.endsWith(".ts")) continue;
|
|
if (file.endsWith(".test.ts")) continue;
|
|
if (file.endsWith(".types.ts")) continue;
|
|
if (file.endsWith("/index.ts")) continue;
|
|
if (file.endsWith("/api-migrations.spec-conformance.test.ts")) {
|
|
continue;
|
|
}
|
|
const md = file.replace(/\.ts$/, ".md");
|
|
try {
|
|
await stat(md);
|
|
} catch {
|
|
missing.push(md);
|
|
}
|
|
}
|
|
expect(missing).toEqual([]);
|
|
});
|
|
});
|