import { describe, expect, it } from "vitest"; import { assertJsonSafe } from "./emit-manifest.js"; describe("assertJsonSafe", () => { it("accepts plain JSON values, including nested objects and arrays", () => { expect(() => assertJsonSafe( { name: "workflow", count: 3, enabled: true, missing: null, tags: ["a", "b"], nested: { list: [1, 2, { deep: "value" }] }, }, "config", ), ).not.toThrow(); }); it("omits undefined-valued object properties without throwing", () => { expect(() => assertJsonSafe({ a: undefined, b: 1 }, "config")).not.toThrow(); }); it.each([ ["function", { a: () => {} }], ["symbol", { a: Symbol("x") }], ["bigint", { a: 1n }], ["NaN", { a: Number.NaN }], ["Infinity", { a: Number.POSITIVE_INFINITY }], ["Map", { a: new Map() }], ["Set", { a: new Set() }], ["Date", { a: new Date(0) }], ["undefined array element", { a: [undefined] }], ])("throws for non-serializable %s", (_label, value) => { expect(() => assertJsonSafe(value, "config")).toThrow(/not JSON-serializable/); }); it("includes the path to the offending value in the error", () => { expect(() => assertJsonSafe({ outer: { inner: () => {} } }, "src/workflows/foo.ts config"), ).toThrow("src/workflows/foo.ts config.outer.inner"); }); });