Files
blog/test/site-config.test.js
T

69 lines
2.5 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 === "Gitea");
assert.ok(gitService, "Gitea service exists");
assert.equal(gitService.url, "https://git.riverrooks.dev/venus");
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 links
const navHome = site.nav.find((n) => n.label === "Home");
assert.ok(navHome, "Nav Home link exists");
assert.equal(navHome.url, "/");
const navCode = site.nav.find((n) => n.label === "Code");
assert.ok(navCode, "Nav Code link exists");
assert.equal(navCode.url, "https://git.riverrooks.dev/venus");
});
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");
});