Files
clean-architecture-frontend…/tests/unit/json-schema.test.ts
T
2026-08-01 19:39:59 +09:00

59 lines
1.8 KiB
TypeScript

import { readFile } from "node:fs/promises";
import { describe, expect, it } from "vitest";
import { assertMatchesJsonSchema } from "../../scripts/lib/json-schema.ts";
async function json(path: string): Promise<unknown> {
return JSON.parse(await readFile(path, "utf8")) as unknown;
}
describe("checked-in JSON Schema execution", () => {
it("accepts a build manifest and rejects undeclared output fields", async () => {
const schema = await json("schemas/artifacts/build-manifest.schema.json");
const manifest = {
schemaVersion: 1,
buildId: "build-1",
commitSha: "commit-1",
releaseId: "release-1",
moduleInventoryHash: "inventory-hash",
generatedAt: "2026-08-01T00:00:00.000Z",
buildContext: {
nodeVersion: "v24.11.0",
packageManagerVersion: "11.17.0",
runnerImage: "test-runner",
sourceDateEpoch: null,
},
outputs: {
directory: "dist",
viteManifest: "dist/.vite/manifest.json",
moduleInventory: "artifacts/quality/vite-module-inventory.json",
routeChunks: { home: "assets/home.js" },
runtimeConfigSchema: "dist/runtime-config.schema.json",
},
};
expect(() =>
assertMatchesJsonSchema(schema, manifest, "build manifest"),
).not.toThrow();
expect(() =>
assertMatchesJsonSchema(
schema,
{ ...manifest, undocumented: true },
"build manifest",
),
).toThrow(/checked-in JSON Schema/u);
});
it("resolves local schema definitions in the recipe catalog", async () => {
const [schema, catalog] = await Promise.all([
json("schemas/config/frontend-capability-recipes.schema.json"),
json("config/recipes/frontend-capability-recipes.json"),
]);
expect(() =>
assertMatchesJsonSchema(schema, catalog, "optional recipe catalog"),
).not.toThrow();
});
});