Initial Commit
This commit is contained in:
53
packages/api-stack/api/api-secrets/tests/dep-graph.test.ts
Normal file
53
packages/api-stack/api/api-secrets/tests/dep-graph.test.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
|
||||
describe("dep-graph", () => {
|
||||
it("runtime deps are exactly the expected set (sorted)", {
|
||||
timeout: 5000,
|
||||
}, () => {
|
||||
const pkg = JSON.parse(
|
||||
readFileSync(join(__dirname, "..", "package.json"), "utf8")
|
||||
) as { dependencies?: Record<string, string> };
|
||||
const runtime = Object.keys(pkg.dependencies ?? {}).sort();
|
||||
expect(runtime).toEqual([
|
||||
"@suaveplan/api-types",
|
||||
"@suaveplan/error",
|
||||
"tslib",
|
||||
"zod",
|
||||
]);
|
||||
});
|
||||
|
||||
it("zero peerDependencies", { timeout: 5000 }, () => {
|
||||
const pkg = JSON.parse(
|
||||
readFileSync(join(__dirname, "..", "package.json"), "utf8")
|
||||
) as { peerDependencies?: Record<string, string> };
|
||||
expect(Object.keys(pkg.peerDependencies ?? {})).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("zod-import-form", () => {
|
||||
it("every src file uses default-import z", { timeout: 5000 }, () => {
|
||||
const { readdirSync, statSync, readFileSync } =
|
||||
require("node:fs") as typeof import("node:fs");
|
||||
function* walk(dir: string): Generator<string> {
|
||||
for (const entry of readdirSync(dir)) {
|
||||
const p = join(dir, entry);
|
||||
if (statSync(p).isDirectory()) {
|
||||
yield* walk(p);
|
||||
} else if (p.endsWith(".ts")) {
|
||||
yield p;
|
||||
}
|
||||
}
|
||||
}
|
||||
const srcDir = join(__dirname, "..", "src");
|
||||
const bad: string[] = [];
|
||||
for (const file of walk(srcDir)) {
|
||||
const src = readFileSync(file, "utf8");
|
||||
if (/import\s*\{\s*z\s*\}\s*from\s*["']zod["']/.test(src)) {
|
||||
bad.push(file);
|
||||
}
|
||||
}
|
||||
expect(bad).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1 @@
|
||||
export {};
|
||||
Reference in New Issue
Block a user