Files
suaveplan/packages/api-stack/api/api-sse/tests/zod-import-form.test.ts
2026-05-27 23:29:53 +01:00

41 lines
1.2 KiB
TypeScript

/**
* Pins the `import z from "zod"` convention across this package.
*
* Any file that imports zod via the named form
* (`import { z } from "zod"`) breaks under Bun and is forbidden by
* memory-rule `feedback_zod_import.md`. This test scans every
* `src/**` file and fails on any non-default import.
*/
import { readdirSync, readFileSync, statSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "@suaveplan/testing/runner";
const SRC = join(__dirname, "..", "src");
function walk(dir: string, out: string[] = []): string[] {
for (const entry of readdirSync(dir)) {
const full = join(dir, entry);
const stat = statSync(full);
if (stat.isDirectory()) {
walk(full, out);
} else if (full.endsWith(".ts")) {
out.push(full);
}
}
return out;
}
describe("zod import form", () => {
it("every src file uses default-import z", () => {
const offenders: string[] = [];
for (const file of walk(SRC)) {
const text = readFileSync(file, "utf8");
if (/import\s*\{\s*z[ ,}]/.test(text)) {
offenders.push(file);
}
}
expect(offenders).toEqual([]);
}, 5000);
});