|
| 1 | +import assert from "node:assert/strict"; |
| 2 | +import { existsSync, readFileSync } from "node:fs"; |
| 3 | +import { dirname, join } from "node:path"; |
| 4 | +import { test } from "node:test"; |
| 5 | +import { fileURLToPath } from "node:url"; |
| 6 | + |
| 7 | +const root = dirname(fileURLToPath(import.meta.url)); |
| 8 | +const html = readFileSync(join(root, "index.html"), "utf8"); |
| 9 | + |
| 10 | +test("every in-page link points at an existing id", () => { |
| 11 | + const ids = new Set([...html.matchAll(/\sid="([^"]+)"/g)].map((match) => match[1])); |
| 12 | + const anchors = [...html.matchAll(/href="#([^"]+)"/g)].map((match) => match[1]); |
| 13 | + |
| 14 | + assert.ok(anchors.length > 0, "expected at least one in-page link"); |
| 15 | + for (const anchor of anchors) { |
| 16 | + assert.ok(ids.has(anchor), `No element has id="${anchor}" for the link to #${anchor}`); |
| 17 | + } |
| 18 | +}); |
| 19 | + |
| 20 | +test("local stylesheets exist", () => { |
| 21 | + const stylesheets = [...html.matchAll(/<link[^>]+rel="stylesheet"[^>]+href="([^"]+)"/g)] |
| 22 | + .map((match) => match[1]) |
| 23 | + .filter((href) => !/^https?:/.test(href)); |
| 24 | + |
| 25 | + assert.ok(stylesheets.length > 0, "expected a local stylesheet"); |
| 26 | + for (const href of stylesheets) { |
| 27 | + assert.ok(existsSync(join(root, href)), `Missing stylesheet ${href}`); |
| 28 | + } |
| 29 | +}); |
| 30 | + |
| 31 | +test("page has a title and a description", () => { |
| 32 | + assert.match(html, /<title>[^<]+<\/title>/); |
| 33 | + assert.match(html, /<meta\s+name="description"\s+content="[^"]+"/); |
| 34 | +}); |
0 commit comments