import test from "node:test"; import assert from "node:assert/strict"; import nunjucks from "nunjucks"; import path from "node:path"; import { extractTerminalPreview, filterTagList, isoDate, postDate, readingTime, renderExcerptMarkdown } from "../src/_filters/index.js"; const includesDir = path.resolve("src/_includes"); function renderFeaturedCard(terminal) { const env = new nunjucks.Environment(new nunjucks.FileSystemLoader(includesDir), { autoescape: false }); env.addFilter("extractTerminalPreview", extractTerminalPreview); env.addFilter("filterTagList", filterTagList); env.addFilter("isoDate", isoDate); env.addFilter("postDate", postDate); env.addFilter("readingTime", readingTime); env.addFilter("renderExcerptMarkdown", renderExcerptMarkdown); const featured = { url: "/dispatches/example/", date: "2026-10-06", data: { featured: true, terminal, tags: ["systems"], title: "Example dispatch", excerpt: "An example featured dispatch used to verify the terminal preview." }, templateContent: `

Terminal preview

Inspect the first five lines:

cat /dispatches/example | head -n 5

Investigation

The public article begins here.

` }; return env.render("partials/featured-card.njk", { collections: { posts: [featured] } }); } test("Featured terminal preview: renders Markdown output only when terminal frontmatter is true", () => { const output = renderFeaturedCard(true); assert.match(output, /class="[^"]*terminal-code-box[^"]*"/); assert.match(output, /Inspect the first five lines:/); assert.match(output, /cat \/dispatches\/example \| head -n 5/); assert.doesNotMatch(output, /Terminal preview/); assert.doesNotMatch(output, /init_cluster\.sh/); }); test("Featured terminal preview: does not render when terminal frontmatter is false or absent", () => { assert.doesNotMatch(renderFeaturedCard(false), /terminal-code-box/); assert.doesNotMatch(renderFeaturedCard(undefined), /terminal-code-box/); });