-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.mjs
More file actions
22 lines (19 loc) · 1014 Bytes
/
Copy pathtest.mjs
File metadata and controls
22 lines (19 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { test } from "node:test";
import assert from "node:assert/strict";
import { readFileSync, existsSync } from "node:fs";
import { join } from "node:path";
const root = new URL("./", import.meta.url).pathname;
const html = readFileSync(join(root, "index.html"), "utf8");
test("every local href/src in index.html exists", () => {
const refs = [...html.matchAll(/(?:href|src)="([^"]+)"/g)].map(m => m[1])
.filter(u => !/^(https?:|mailto:|tel:|#|data:)/.test(u))
.map(u => u.replace(/[?#].*$/, ""));
const missing = refs.filter(u => !existsSync(join(root, u.replace(/^\//, ""))));
assert.deepEqual(missing, []);
});
test("sitemap urls exist", () => {
const sm = readFileSync(join(root, "sitemap.xml"), "utf8");
const paths = [...sm.matchAll(/<loc>https?:\/\/[^/]+(\/[^<]*)<\/loc>/g)].map(m => m[1]);
const missing = paths.filter(p => { const f = p.replace(/^\//, ""); return !(existsSync(join(root, f)) || existsSync(join(root, f, "index.html"))); });
assert.deepEqual(missing, []);
});