Files
action-topology-engine/tests/schema.test.ts
2026-06-24 09:47:23 +08:00

22 lines
872 B
TypeScript

import assert from "node:assert/strict";
import { mkdtemp, readFile, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { test } from "node:test";
import Ajv from "ajv";
import { scanUrl } from "../src/engine.js";
test("topology graph JSON schema validates emitted scan artifacts", async () => {
const schema = JSON.parse(await readFile("schemas/topology-graph.schema.json", "utf8"));
const ajv = new Ajv({ allErrors: true });
const validate = ajv.compile(schema);
const dir = await mkdtemp(path.join(tmpdir(), "action-topology-schema-test-"));
try {
const graph = await scanUrl({ url: "examples/simple.html", out: path.join(dir, "graph.json") });
assert.equal(validate(graph), true, JSON.stringify(validate.errors, null, 2));
} finally {
await rm(dir, { recursive: true, force: true });
}
});