Files
mesh-catalog/modules/gitea/test/kept.test.ts
T

21 lines
1.2 KiB
TypeScript

import assert from "node:assert/strict";
import { test } from "node:test";
import { readFileSync } from "node:fs";
// 1790: the states the module announces are the states its manifest declares, no more, no fewer; none is readable
// because no other module's manifest reads one of them.
test("the states the module announces are the states its manifest declares", async () => {
const { KEPT } = await import("../kept.ts");
const manifest = JSON.parse(readFileSync(new URL("../module.json", import.meta.url), "utf8"));
const declared = (manifest.state as (string | { name: string })[]).map((s) => (typeof s === "string" ? s : s.name)).sort();
assert.deepEqual(KEPT.map((k) => k.name).sort(), declared);
assert.ok(KEPT.every((k) => !k.readable), "no other module's manifest reads a state of gitea");
});
test("index.ts announces the list through the SDK before it serves", () => {
const source = readFileSync(new URL("../index.ts", import.meta.url), "utf8");
assert.match(source, /import \{ keeps \} from "@novox\/mesh-sdk\/state"/);
assert.match(source, /await keeps\(KEPT\)/);
assert.ok(source.indexOf("await keeps(KEPT)") < source.indexOf("registerModuleTools(\"gitea\""), "keeps comes before the tools are served");
});