61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { test } from "node:test";
|
|
import { buildEmptyGraph } from "../src/metadata.js";
|
|
|
|
const graphArgs = {
|
|
inputUrl: "./examples/simple.html",
|
|
entryUrl: "file:///examples/simple.html",
|
|
mode: "scan" as const,
|
|
};
|
|
|
|
test("input fingerprint is stable for the same input and mode", () => {
|
|
const first = buildEmptyGraph(graphArgs);
|
|
const second = buildEmptyGraph(graphArgs);
|
|
|
|
assert.equal(first.metadata.inputFingerprint, second.metadata.inputFingerprint);
|
|
});
|
|
|
|
test("crawl session id is unique for each generated graph", () => {
|
|
const first = withFixedDate(() => buildEmptyGraph(graphArgs));
|
|
const second = withFixedDate(() => buildEmptyGraph(graphArgs));
|
|
|
|
assert.notEqual(first.metadata.crawlSessionId, second.metadata.crawlSessionId);
|
|
});
|
|
|
|
test("empty graph starts with a machine-readable summary", () => {
|
|
const graph = buildEmptyGraph(graphArgs);
|
|
|
|
assert.deepEqual(graph.summary, {
|
|
states: 0,
|
|
elements: 0,
|
|
edges: 0,
|
|
skippedActions: 0,
|
|
failedObservations: 0,
|
|
failedObservationsByReason: {},
|
|
skippedActionsByRiskCategory: {},
|
|
edgesByRiskCategory: {},
|
|
});
|
|
});
|
|
|
|
function withFixedDate<T>(callback: () => T): T {
|
|
const RealDate = Date;
|
|
const fixedTime = new RealDate("2026-06-16T00:00:00.000Z").getTime();
|
|
|
|
class FixedDate extends RealDate {
|
|
constructor(value?: string | number | Date) {
|
|
super(value ?? fixedTime);
|
|
}
|
|
|
|
static now(): number {
|
|
return fixedTime;
|
|
}
|
|
}
|
|
|
|
globalThis.Date = FixedDate as DateConstructor;
|
|
try {
|
|
return callback();
|
|
} finally {
|
|
globalThis.Date = RealDate;
|
|
}
|
|
}
|