Initial Commit
This commit is contained in:
29
packages/api-stack/api/api-router/tests/dep-graph.test.ts
Normal file
29
packages/api-stack/api/api-router/tests/dep-graph.test.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
|
||||
describe("dep-graph", () => {
|
||||
it("pins exact runtime dependency set", { timeout: 5000 }, () => {
|
||||
const pkg = JSON.parse(
|
||||
readFileSync(new URL("../package.json", import.meta.url), "utf8")
|
||||
) as {
|
||||
dependencies: Record<string, string>;
|
||||
};
|
||||
expect(Object.keys(pkg.dependencies).sort()).toEqual(
|
||||
[
|
||||
"@suaveplan/api-types",
|
||||
"@suaveplan/error",
|
||||
"@suaveplan/types",
|
||||
"tslib",
|
||||
"zod",
|
||||
].sort()
|
||||
);
|
||||
});
|
||||
|
||||
it("root barrel has no export-star", { timeout: 5000 }, () => {
|
||||
const src = readFileSync(
|
||||
new URL("../src/index.ts", import.meta.url),
|
||||
"utf8"
|
||||
);
|
||||
expect(src.includes("export *")).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
import { webcrypto } from "node:crypto";
|
||||
|
||||
type WritableGlobal = { crypto?: Crypto };
|
||||
const g = globalThis as WritableGlobal;
|
||||
if (g.crypto === undefined) {
|
||||
g.crypto = webcrypto as unknown as Crypto;
|
||||
}
|
||||
56
packages/api-stack/api/api-router/tests/subpaths.test.ts
Normal file
56
packages/api-stack/api/api-router/tests/subpaths.test.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
|
||||
describe("subpath exports", () => {
|
||||
it("router subpath imports", { timeout: 5000 }, async () => {
|
||||
const mod = await import("../src/router/index.js");
|
||||
expect(mod.Router).toBeDefined();
|
||||
});
|
||||
|
||||
it("request subpath imports", { timeout: 5000 }, async () => {
|
||||
const mod = await import("../src/request/index.js");
|
||||
expect(mod.MapHeaders).toBeDefined();
|
||||
});
|
||||
|
||||
it("response subpath imports", { timeout: 5000 }, async () => {
|
||||
const mod = await import("../src/response/index.js");
|
||||
expect(mod.createResponse).toBeDefined();
|
||||
expect(mod.ResponseBuilder).toBeDefined();
|
||||
expect(mod.ok).toBeDefined();
|
||||
expect(mod.jsonResponse).toBeDefined();
|
||||
});
|
||||
|
||||
it("route-options subpath imports", { timeout: 5000 }, async () => {
|
||||
const mod = await import("../src/route-options/index.js");
|
||||
expect(mod.routeOptionsSchema).toBeDefined();
|
||||
expect(mod.parseRouteOptions).toBeDefined();
|
||||
expect(mod.safeParseRouteOptions).toBeDefined();
|
||||
});
|
||||
|
||||
it("middleware subpath imports", { timeout: 5000 }, async () => {
|
||||
const mod = await import("../src/middleware/index.js");
|
||||
expect(mod.composeMiddleware).toBeDefined();
|
||||
expect(mod.assertPluginInsertionStep).toBeDefined();
|
||||
expect(mod.PLUGIN_INSERTION_STEP).toBe("post-validation");
|
||||
});
|
||||
|
||||
it("route-match subpath imports", { timeout: 5000 }, async () => {
|
||||
const mod = await import("../src/route-match/index.js");
|
||||
expect(mod.createRouteMatch).toBeDefined();
|
||||
});
|
||||
|
||||
it("slot subpath imports", { timeout: 5000 }, async () => {
|
||||
const mod = await import("../src/slot/index.js");
|
||||
expect(mod.InMemoryBlueGreenSlot).toBeDefined();
|
||||
});
|
||||
|
||||
it("error-codes subpath imports", { timeout: 5000 }, async () => {
|
||||
const mod = await import("../src/error-codes/index.js");
|
||||
expect(mod.ROUTER_CODES).toBeDefined();
|
||||
expect(mod.RouterError).toBeDefined();
|
||||
});
|
||||
|
||||
it("testing subpath imports", { timeout: 5000 }, async () => {
|
||||
const mod = await import("../src/testing/index.js");
|
||||
expect(mod.runRouterConformance).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
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([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user