29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it } from "@suaveplan/testing/runner";
|
|
|
|
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 (entry.endsWith(".ts")) out.push(full);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
describe("zod import form", () => {
|
|
it("every src file uses default-import z", { timeout: 5000 }, () => {
|
|
const srcDir = new URL("../src", import.meta.url).pathname;
|
|
const offenders: string[] = [];
|
|
for (const file of walk(srcDir)) {
|
|
const content = readFileSync(file, "utf8");
|
|
// Match `import { z }` or `import { z, ... }` from "zod"
|
|
if (/import\s*\{\s*z[\s,}]/.test(content)) {
|
|
offenders.push(file);
|
|
}
|
|
}
|
|
expect(offenders).toEqual([]);
|
|
});
|
|
});
|