Something went wrong. Try again.
about things notes.zzstoatzz.io
notes
Something went wrong. Try again.
JavaScript
123456789101112131415161718192021222324252627282930313233343536373839404142import { describe, expect, test } from "bun:test";import { createNavigationCoordinator, internalDocRoute, resolveDocLink,} from "../site/navigation.js";
const routeFor = (path) => path.replace(/^\/+|\/+$/g, "").replace(/\.md$/i, "").replace(/(^|\/)README$/i, "$1").replace(/\/$/, "");
describe("document navigation", () => { test("resolves a README sibling to its canonical route", () => { expect(resolveDocLink("./cost-declaration.md", "operations/home-infra/README.md")).toBe( "operations/home-infra/cost-declaration.md", ); expect( internalDocRoute( "./cost-declaration.md", "operations/home-infra/README.md", routeFor, ), ).toBe("operations/home-infra/cost-declaration"); });
test("leaves external, in-page, and asset links alone", () => { for (const href of ["https://example.com", "mailto:a@example.com", "#heading", "./plot.png"]) { expect(internalDocRoute(href, "operations/home-infra/README.md", routeFor)).toBeNull(); } });
test("invalidates and aborts an older navigation", () => { const coordinator = createNavigationCoordinator(); const first = coordinator.begin(); const second = coordinator.begin();
expect(first.signal.aborted).toBe(true); expect(first.isCurrent()).toBe(false); expect(second.signal.aborted).toBe(false); expect(second.isCurrent()).toBe(true); });});