import { describe, it, expect } from "vitest"; import { ensureHfIds, mintHfId } from "./hfIds.js"; import { parseHTML } from "linkedom"; function ids(html: string): string[] { const { document } = parseHTML(html); return Array.from(document.querySelectorAll("[data-hf-id]")).map( (e) => e.getAttribute("data-hf-id") as string, ); } // data-hf-id of the first element matching `selector`. function idOf(html: string, selector: string): string | null { const { document } = parseHTML(html); return document.querySelector(selector)?.getAttribute("data-hf-id") ?? null; } const doc = (body: string) => `
${body}`; describe("ensureHfIds", () => { it("mints a hf- id on every editable element node in body", () => { const html = `
xkeep
`; const out = ensureHfIds(html); // only thegets an id expect(ids(out)).toHaveLength(1); expect(out).not.toContain("