import { test } from "node:test"; import assert from "node:assert/strict"; import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { articlesPublicDir } from "./articles"; import { FOOTER_NAV, HEADER_NAV } from "./nav"; // Run with: pnpm --filter homepage test // // Where /articles/ reads (release 26 A3): public/, or the e2e fixture outside a // production build while it holds an index; and the nav names it always. test("the fixture dir is read only outside a production build, and only while it holds an article index", () => { const fixture = fs.mkdtempSync(path.join(os.tmpdir(), "homepage-articles-")); try { const env = { E2E_ARTICLES_PUBLIC_DIR: fixture }; assert.equal(articlesPublicDir(env, "/pub"), "/pub", "no index yet"); fs.mkdirSync(path.join(fixture, "articles")); fs.writeFileSync(path.join(fixture, "articles", "index.json"), "{}"); assert.equal(articlesPublicDir(env, "/pub"), fixture); assert.equal(articlesPublicDir({ ...env, NODE_ENV: "production" }, "/pub"), "/pub"); assert.equal(articlesPublicDir({}, "/pub"), "/pub"); } finally { fs.rmSync(fixture, { recursive: true, force: true }); } }); test("Articles is in the header and the footer, unconditionally", () => { assert.ok(HEADER_NAV.some((n) => n.href === "/articles/" && n.label === "Articles")); assert.ok(FOOTER_NAV.some((n) => n.href === "/articles/")); });