Unit tests go to tests/unit/<area>/, browser smoke tests to tests/smoke/<area>/, and tests against a running desktop app to tests/native/. Files named after dates, work passes, or Kanban cards get feature names, for example editorOctober12 -> editor/footnotes. scripts/ keeps the build, release, and package tools. Plugin repositories import scripts/packagePlugin.mjs, and the Terminal smoke test imports scripts/pluginMocks.mjs, which now re-exports the harness copy. The unit tests get their own type check (tests/tsconfig.json) with Node types. pnpm check runs it after the app check. Add @types/node and fix the three test mocks that it reported.
34 lines
1.5 KiB
TypeScript
34 lines
1.5 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import MarkdownIt from "markdown-it";
|
|
import { footnotes, renderFootnotes } from "../../../src/lib/editor/footnotes.ts";
|
|
|
|
function render(source: string) {
|
|
const markdown = new MarkdownIt({ html: false }).use(footnotes);
|
|
const env = {};
|
|
return markdown.render(source, env) + renderFootnotes(markdown, env);
|
|
}
|
|
|
|
test("footnotes use first-reference order, repeated backlinks, and rich multiline definitions", () => {
|
|
const html = render("First[^b], then[^a], again[^b].\n\n[^a]: Second definition\n[^b]: **Bold** text\n continued\n\n Second paragraph.\n");
|
|
assert.match(html, /id="rs-fnref-1-1"/);
|
|
assert.match(html, /id="rs-fnref-1-2"/);
|
|
assert.match(html, /<strong>Bold<\/strong> text\ncontinued/);
|
|
assert.match(html, /<p>Second paragraph\.<\/p>/);
|
|
assert.ok(html.indexOf('<li id="rs-fn-1"') < html.indexOf('<li id="rs-fn-2"'));
|
|
assert.match(html, /href="#rs-fnref-1-2"/);
|
|
});
|
|
|
|
test("undefined, escaped, inline-code, fenced-code, and indented-code references stay literal", () => {
|
|
const html = render("Missing[^missing]. Escaped\\[^n]. `[^n]`\n\n```md\n[^n]\n```\n\n [^n]\n\n[^n]: Unused\n");
|
|
assert.doesNotMatch(html, /md-footnotes|md-footnote-ref/);
|
|
assert.match(html, /Missing\[\^missing\]/);
|
|
});
|
|
|
|
test("footnotes keep HTML escaped and support CRLF", () => {
|
|
const html = render("Body[^x]\r\n\r\n[^x]: <script>alert(1)</script>\r\n");
|
|
assert.match(html, /<script>/);
|
|
assert.doesNotMatch(html, /<script>/);
|
|
assert.match(html, /Footnote 1/);
|
|
});
|