Something went wrong. Try again.
Web frontend and supporting services for lance.blue
Something went wrong. Try again.
2.2 kB · 57 lines
JavaScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758/** * The project's off-site addresses are in one list, and three files show them. * * project-links.ts is read by both footers — Footer.astro at build time, * chrome.ts at run time — so those two cannot drift from each other. What can * drift is a URL written by hand somewhere else: the FAQ carried * `tangled.net/lance.blue`, which answers 404, for as long as nothing compared * it to anything. * * Run with `npm test`. */import { test } from "node:test";import assert from "node:assert/strict";import { readFile } from "node:fs/promises";import { join } from "node:path";
const web = join(new URL(".", import.meta.url).pathname, "..");const read = (path) => readFile(join(web, path), "utf8");
const links = await read("src/project-links.ts");const astroFooter = await read("src/components/Footer.astro");const chrome = await read("src/chrome.ts");const faq = await read("src/content/faq.json");
const hrefs = [...links.matchAll(/href:\s*"([^"]+)"/g)].map((m) => m[1]);assert.ok(hrefs.length >= 2, "project-links.ts no longer declares hrefs");
test("both footers render the list rather than their own copy", () => { for (const [name, source] of [ ["Footer.astro", astroFooter], ["chrome.ts", chrome], ]) { assert.match(source, /PROJECT_LINKS/, `${name} does not read the list`); assert.doesNotMatch( source, /https:\/\/(bsky\.app|tangled\.)/, `${name} writes an address the list already holds`, ); }});
test("the FAQ points at the same hosts the footer does", () => { // Same first label, different host: tangled.net against tangled.org, or a // bsky.social profile URL against bsky.app. Anything sharing no label with // a project link is some other site and is not this test's business. const known = new Map( hrefs .map((href) => new URL(href).host) .map((host) => [host.split(".")[0], host]), ); for (const [, url] of faq.matchAll(/"(https:\/\/[^"]+)"/g)) { const host = new URL(url).host; const expected = known.get(host.split(".")[0]); if (!expected) continue; assert.equal(host, expected, `faq.json points at ${host}, not ${expected}`); }});