Something went wrong. Try again.
Web frontend and supporting services for lance.blue
Something went wrong. Try again.
2.1 kB · 48 lines
JavaScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849/** * sequoia.json describes the same site Astro builds. * * A standard.site document record carries the post's address, and sequoia * computes it as siteUrl + pathPrefix + "/" + slug. Astro computes the same * address from its own `site`. Nothing connects the two files, so if either * moves the records point somewhere that does not serve the post - and * because the record is keyed by that path, the next publish does not correct * the old one, it writes a second record beside it. * * Run with `npm test`, which builds first: this reads dist/. */import { test } from "node:test";import assert from "node:assert/strict";import { readFile, readdir } from "node:fs/promises";
const url = (path) => new URL(path, import.meta.url);
const sequoia = JSON.parse(await readFile(url("../sequoia.json"), "utf8"));const astro = (await import("../astro.config.mjs")).default;
test("sequoia.json and astro.config.mjs agree on the site", () => { assert.equal(sequoia.siteUrl, astro.site); // A trailing slash would make Astro's canonical /blog/x/ while the record // still claims /blog/x, and the two would stop being the same address. assert.equal(astro.trailingSlash, "never");});
test("every built post is canonical at the address its record will claim", async () => { // dist/ rather than the content directory: drafts are already excluded, and // this is the page a reader following the record actually gets. const slugs = await readdir(url("../dist/blog/"), { withFileTypes: true }); const posts = slugs.filter((e) => e.isDirectory()); assert.ok(posts.length > 0, "no posts were built");
for (const post of posts) { const html = await readFile( url(`../dist/blog/${post.name}/index.html`), "utf8", ); // The exact string web/scripts/publish.sh looks for on the live site. const claimed = `${sequoia.siteUrl}${sequoia.pathPrefix}/${post.name}`; assert.ok( html.includes(`rel="canonical" href="${claimed}"`), `dist/blog/${post.name} is not canonical at ${claimed}`, ); }});