import { describe, expect, it, beforeEach, afterEach } from "bun:test"; import { toXml } from "@/output"; describe("toXml", () => { it("wraps results in root element", () => { const out = toXml([{ id: "1", name: "Foo" }]); expect(out).toStartWith(""); expect(out).toEndWith(""); }); it("renders each item as an element with attributes", () => { const out = toXml([{ id: "abc", name: "My Project" }]); expect(out).toContain(''); }); it("renders an empty for empty array", () => { const out = toXml([]); expect(out).toBe("\n\n"); }); it("renders multiple items", () => { const out = toXml([ { id: "1", name: "A" }, { id: "2", name: "B" }, ]); expect(out).toContain('id="1"'); expect(out).toContain('id="2"'); }); it("escapes & in attribute values", () => { const out = toXml([{ name: "Canvas & Codegen" }]); expect(out).toContain("Canvas & Codegen"); expect(out).not.toContain("Canvas & Codegen"); }); it("escapes < and > in attribute values", () => { const out = toXml([{ name: "" }]); expect(out).toContain("<tag>"); }); it("escapes quotes in attribute values", () => { const out = toXml([{ name: 'say "hi"' }]); expect(out).toContain(""hi""); }); it("renders nested objects as child elements", () => { const out = toXml([ { id: "1", state: { name: "Todo", group: "unstarted" } }, ]); expect(out).toContain(" { const out = toXml([{ id: "1", tags: ["a", "b"] }]); expect(out).toContain(""); expect(out).toContain(""); }); it("renders primitive array items as text nodes", () => { const out = toXml([{ id: "1", assignees: ["uuid-1", "uuid-2"] }]); expect(out).toContain("uuid-1"); expect(out).toContain("uuid-2"); }); it("escapes special chars in primitive array items", () => { const out = toXml([{ id: "1", labels: ["a & b"] }]); expect(out).toContain("a & b"); }); it("handles null values as empty string in attributes", () => { const out = toXml([{ id: "1", color: null }]); expect(out).toContain('color=""'); }); }); describe("argv stripping", () => { it("removes --json from process.argv when present", async () => { process.argv.push("--json-test-flag-xyz"); // The module is already loaded; test that toXml is a function (module loaded ok) expect(typeof toXml).toBe("function"); process.argv.pop(); }); it("jsonMode and xmlMode are booleans", async () => { const { jsonMode, xmlMode } = await import("@/output"); expect(typeof jsonMode).toBe("boolean"); expect(typeof xmlMode).toBe("boolean"); }); });