- Update AGENTS.md and .agents/rules/blog-system.md with strict TDD mandate - Extract Eleventy custom filters into modular src/_filters/index.js for unit testing - Add npm test script using Node.js native test runner (node:test) - Create test/site-config.test.js for environment validation and fatal error assertions - Create test/filters.test.js for adversarial filter edge cases (dates, limits, reading time, headings) - Create test/frontmatter-schema.test.js enforcing post metadata contracts - Create test/design-rules.test.js enforcing strict anti-patterns (no glassmorphism, no shadows, max 4px radius) - Create test/build-integrity.test.js checking static output, zero 404 links, and TOC anchor targets
65 lines
2.4 KiB
JavaScript
65 lines
2.4 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { execSync } from "node:child_process";
|
|
|
|
test("Site Config: throws explicit error when SITE_DOMAIN is unset", () => {
|
|
// Run isolated Node process with empty environment to verify error throw
|
|
const cmd = `node -e '
|
|
process.env.SITE_DOMAIN = "";
|
|
delete process.env.SITE_DOMAIN;
|
|
// mock empty cwd without .env
|
|
process.chdir("/tmp");
|
|
import("${process.cwd()}/src/_data/site.js")
|
|
.then(() => process.exit(0))
|
|
.catch(err => {
|
|
if (err.message.includes("FATAL CONFIGURATION ERROR: SITE_DOMAIN")) {
|
|
process.exit(42);
|
|
}
|
|
process.exit(1);
|
|
});
|
|
'`;
|
|
|
|
try {
|
|
execSync(cmd, { stdio: "pipe" });
|
|
assert.fail("Should have thrown error when SITE_DOMAIN is missing");
|
|
} catch (err) {
|
|
assert.equal(err.status, 42, "Process exited with status 42 (expected error caught)");
|
|
}
|
|
});
|
|
|
|
test("Site Config: correctly parses SITE_DOMAIN and derives service subdomains", async () => {
|
|
process.env.SITE_DOMAIN = "testcluster.internal";
|
|
delete process.env.SITE_URL;
|
|
|
|
// Import site configuration dynamically
|
|
const { default: site } = await import(`../src/_data/site.js?t=${Date.now()}`);
|
|
|
|
assert.equal(site.domain, "testcluster.internal");
|
|
assert.equal(site.url, "https://testcluster.internal");
|
|
|
|
// Verify dynamic subdomains
|
|
const gitService = site.services.find((s) => s.name === "Forgejo Git");
|
|
assert.ok(gitService, "Forgejo Git service exists");
|
|
assert.equal(gitService.url, "https://git.testcluster.internal");
|
|
assert.equal(gitService.tag, "git.testcluster.internal:2222");
|
|
|
|
const chefService = site.services.find((s) => s.name === "CyberChef");
|
|
assert.ok(chefService, "CyberChef service exists");
|
|
assert.equal(chefService.url, "https://chef.testcluster.internal");
|
|
|
|
// Verify navigation Git Forge URL
|
|
const navGit = site.nav.find((n) => n.label === "Git Forge");
|
|
assert.ok(navGit, "Nav Git Forge link exists");
|
|
assert.equal(navGit.url, "https://git.testcluster.internal");
|
|
});
|
|
|
|
test("Site Config: respects explicit SITE_URL override", async () => {
|
|
process.env.SITE_DOMAIN = "riverrooks.dev";
|
|
process.env.SITE_URL = "http://localhost:8080";
|
|
|
|
const { default: site } = await import(`../src/_data/site.js?t=${Date.now()}`);
|
|
|
|
assert.equal(site.domain, "riverrooks.dev");
|
|
assert.equal(site.url, "http://localhost:8080");
|
|
});
|