61 lines
2.0 KiB
JavaScript
61 lines
2.0 KiB
JavaScript
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
|
|
} 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);
|
|
|
|
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: `
|
|
<h1 id="terminal-preview">Terminal preview</h1>
|
|
<p>Inspect the first five lines:</p>
|
|
<pre><code class="language-bash">cat /dispatches/example | head -n 5</code></pre>
|
|
<h1 id="investigation">Investigation</h1>
|
|
<p>The public article begins here.</p>
|
|
`
|
|
};
|
|
|
|
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/);
|
|
});
|