47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
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): readonly string[] {
|
|
const out: string[] = [];
|
|
for (const entry of readdirSync(dir)) {
|
|
const full = join(dir, entry);
|
|
if (statSync(full).isDirectory()) {
|
|
out.push(...walk(full));
|
|
} else if (full.endsWith(".ts")) {
|
|
out.push(full);
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
|
|
describe("zod import form", () => {
|
|
it("every src file uses default-import z", { timeout: 5000 }, () => {
|
|
const bad: string[] = [];
|
|
const files = walk(SRC);
|
|
for (const file of files) {
|
|
const text = readFileSync(file, "utf8");
|
|
if (/import\s*\{\s*z\s*[},]/.test(text)) {
|
|
bad.push(file);
|
|
}
|
|
}
|
|
expect(bad).toEqual([]);
|
|
});
|
|
|
|
it("source files importing zod use the default form", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
let imports = 0;
|
|
for (const file of walk(SRC)) {
|
|
const text = readFileSync(file, "utf8");
|
|
if (/from\s+["']zod["']/.test(text)) {
|
|
imports++;
|
|
expect(text).toMatch(/import\s+z\s+from\s+["']zod["']/);
|
|
}
|
|
}
|
|
expect(imports).toBeGreaterThan(0);
|
|
});
|
|
});
|