Files
suaveplan/packages/api-stack/api/wasm-compiler-javy/src/manifest/manifest.test.ts
2026-05-27 23:29:53 +01:00

69 lines
2.5 KiB
TypeScript

import { describe, expect, it } from "@suaveplan/testing/runner";
import { COMPILER_ABI_VERSION, writeManifest } from "./manifest.js";
describe("writeManifest", () => {
it("emits a manifest mirroring the supplied routes", {
timeout: 5000,
}, async () => {
const writes: Array<[string, string]> = [];
const manifest = await writeManifest({
manifestPath: "/tmp/x.wasm.json",
routes: [
{ method: "GET", path: "/a" },
{ method: "POST", path: "/b" },
],
bundledJs: "var plugin = {};",
javyVersion: "v8.1.1",
compilerVersion: "0.1.0",
compiledAt: "2026-01-01T00:00:00.000Z",
fsWrite: async (p, d) => {
writes.push([p, d]);
},
});
expect(manifest.routes).toHaveLength(2);
expect(manifest.abiVariant).toBe("wasi-stdio");
expect(manifest.abiVersion).toBe(COMPILER_ABI_VERSION);
expect(manifest.javyVersion).toBe("v8.1.1");
expect(manifest.compilerVersion).toBe("0.1.0");
expect(manifest.compiledAt).toBe("2026-01-01T00:00:00.000Z");
expect(manifest.sourceDigest).toHaveLength(64);
expect(writes).toHaveLength(1);
expect(writes[0]?.[0]).toBe("/tmp/x.wasm.json");
const reparsed = JSON.parse(writes[0]?.[1] ?? "{}");
expect(reparsed.routes).toHaveLength(2);
});
it("raises MANIFEST_MISSING_ROUTES on empty routes", {
timeout: 5000,
}, async () => {
await expect(
writeManifest({
manifestPath: "/tmp/x.wasm.json",
routes: [],
bundledJs: "",
javyVersion: "v8.1.1",
compilerVersion: "0.1.0",
fsWrite: async () => undefined,
})
).rejects.toMatchObject({
code: "WASM_COMPILER.MANIFEST_MISSING_ROUTES",
});
});
it("defaults compiledAt to the current ISO timestamp", {
timeout: 5000,
}, async () => {
const manifest = await writeManifest({
manifestPath: "/tmp/y.wasm.json",
routes: [{ method: "GET", path: "/x" }],
bundledJs: "var plugin = {};",
javyVersion: "v8.1.1",
compilerVersion: "0.1.0",
fsWrite: async () => undefined,
});
// ISO 8601 format check
expect(manifest.compiledAt.endsWith("Z")).toBe(true);
expect(manifest.compiledAt.includes("T")).toBe(true);
});
});