Initial Commit
This commit is contained in:
40
packages/api-stack/api/api-sse/tests/zod-import-form.test.ts
Normal file
40
packages/api-stack/api/api-sse/tests/zod-import-form.test.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* 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);
|
||||
});
|
||||
Reference in New Issue
Block a user