38 lines
1.6 KiB
JavaScript
38 lines
1.6 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
extractTerminalPreview,
|
|
removeTerminalPreview
|
|
} from "../src/_filters/index.js";
|
|
|
|
test("Terminal previews: extracts rendered Markdown between the leading preview and article headings", () => {
|
|
const renderedPost = `
|
|
<h1 id="terminal-preview">Terminal preview</h1>
|
|
<p>Use the following command:</p>
|
|
<pre class="language-bash"><code class="language-bash">cat /dispatches/example | head -n 5</code></pre>
|
|
<h1 id="investigation">Investigation</h1>
|
|
<p>The public article starts here.</p>
|
|
`;
|
|
|
|
assert.equal(
|
|
extractTerminalPreview(renderedPost),
|
|
`\n <p>Use the following command:</p>\n <pre class="language-bash"><code class="language-bash">cat /dispatches/example | head -n 5</code></pre>\n `
|
|
);
|
|
assert.equal(
|
|
removeTerminalPreview(renderedPost),
|
|
`\n <h1 id="investigation">Investigation</h1>\n <p>The public article starts here.</p>\n `
|
|
);
|
|
});
|
|
|
|
test("Terminal previews: ignores missing, misplaced, and malformed preview headings", () => {
|
|
const regularPost = "<h1 id=\"article\">Article</h1><p>Visible text.</p>";
|
|
const misplacedPreview = "<h1 id=\"article\">Article</h1><h1 id=\"terminal-preview\">Terminal preview</h1><p>Do not extract.</p>";
|
|
|
|
assert.equal(extractTerminalPreview(regularPost), "");
|
|
assert.equal(removeTerminalPreview(regularPost), regularPost);
|
|
assert.equal(extractTerminalPreview(misplacedPreview), "");
|
|
assert.equal(removeTerminalPreview(misplacedPreview), misplacedPreview);
|
|
assert.equal(extractTerminalPreview(null), "");
|
|
assert.equal(removeTerminalPreview(null), "");
|
|
});
|