import assert from "node:assert/strict"; import { suite, test } from "node:test"; import { resolveRefs } from "./resolve-refs.js"; import type { Element } from "antihtml"; suite("function resolveRefs", () => { test("root to root relative href", () => { const el = resolveRefs(Link, "/"); assert.equal((el as Element).attributes.get("href"), "page.html"); }); test("root to subdir relative href", () => { const el = resolveRefs(Link, "/"); assert.equal((el as Element).attributes.get("href"), "dir/page.html"); }); test("subdir to root relative href", () => { const el = resolveRefs(Link, "/subdir"); assert.equal((el as Element).attributes.get("href"), "../page.html"); }); test("subdir to subdir relative href", () => { const el = resolveRefs(Link, "/subdir"); assert.equal((el as Element).attributes.get("href"), "../alt/page.html"); }); test("nested element", () => { const el = resolveRefs(
Content with Link
, "/"); assert.equal((el.childNodes[1] as Element).attributes.get("href"), "page.html"); }); test("returns element if no changes", () => { const el =
Content with emphasis
; const resEl = resolveRefs(el, "/"); assert.equal(el, resEl); }); test("returns new element if changed", () => { const el =
Content with Link
; const resEl = resolveRefs(el, "/"); assert.notEqual(el, resEl); }); test("does not modify input", () => { const elFn = () =>
Content with Link
; const el = elFn(); resolveRefs(el, "/"); assert.deepEqual(el, elFn()); }); });