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 === "Gitea"); assert.ok(gitService, "Gitea 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 === "Gitea"); assert.ok(navGit, "Nav Gitea 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"); });