50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { readdirSync, readFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it } from "@suaveplan/testing/runner";
|
|
|
|
const SRC_ROOT = join(__dirname, "..", "src");
|
|
|
|
function walk(dir: string, out: string[] = []): string[] {
|
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
const p = join(dir, entry.name);
|
|
if (entry.isDirectory()) {
|
|
if (entry.name === "node_modules" || entry.name === "dist")
|
|
continue;
|
|
walk(p, out);
|
|
} else if (
|
|
entry.name.endsWith(".ts") &&
|
|
!entry.name.endsWith(".test.ts") &&
|
|
!entry.name.endsWith(".bench.ts")
|
|
) {
|
|
out.push(p);
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
|
|
describe("source-tree hygiene", () => {
|
|
it("src tree contains zero Math.random references", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
const files = walk(SRC_ROOT);
|
|
const hits: string[] = [];
|
|
for (const f of files) {
|
|
const content = readFileSync(f, "utf8");
|
|
if (/\bMath\.random\b/.test(content)) hits.push(f);
|
|
}
|
|
expect(hits).toEqual([]);
|
|
});
|
|
|
|
it("src tree contains zero biome-ignore directives", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
const files = walk(SRC_ROOT);
|
|
const hits: string[] = [];
|
|
for (const f of files) {
|
|
const content = readFileSync(f, "utf8");
|
|
if (/biome-ignore/.test(content)) hits.push(f);
|
|
}
|
|
expect(hits).toEqual([]);
|
|
});
|
|
});
|