Skip to content

Commit 17fcf93

Browse files
Check landing page links in CI
1 parent a494216 commit 17fcf93

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,7 @@ jobs:
6262

6363
- name: Build
6464
run: npm run build
65+
66+
- name: Check landing page links
67+
working-directory: website
68+
run: node --test links.test.mjs

‎website/links.test.mjs‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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

Comments
 (0)