testImagesInPages

tcmts.site.testImagesInPages · #tjqm343n · term

An image in a page is one of IMAGES, shown in the page (a data URL, so the site serves no file for it), and the target that shows it full size; an image that isn't one is a problem

import { highlighter, IMAGES, pageList, renderPage, SOURCES } from "#codebase/tcmts/site";
import assert from "node:assert/strict";

export const testImagesInPages = async () => {
  const pages = pageList(SOURCES["docs/README.md"]!);
  const page = pages.find((p) => p.src === "docs/introduction.md")!;
  const hl = await highlighter();
  const r = renderPage(
    page,
    pages,
    "![The codebase](images/tcm.svg)\n\n![Nothing](images/none.svg)",
    hl,
    () => true,
    false,
  );
  assert.match(
    r.html,
    /<a class="image" id="image-tcm" href="#image-tcm" title="Full size"><img src="data:image\/svg\+xml,<svg /,
  );
  assert.match(r.html, /alt="The codebase"><\/a><a class="image-close" href="#image-tcm-closed">/);
  assert.ok(r.ids.includes("image-tcm"));
  const src = /src="([^"]*)"/.exec(r.html)![1]!;
  assert.equal(
    decodeURIComponent(src.slice("data:image/svg+xml,".length)),
    IMAGES["docs/images/tcm.svg"],
  );
  assert.deepEqual(r.problems, ["image images/none.svg: no such image (tcmts.site.IMAGES)"]);
}

uses