Files
RuneStone/tests/unit/links/markdownLinks.spec.ts
T
Knotty Wyvern e433bed28e Move the tests from scripts/ to tests/ by feature
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.
2026-10-27 19:47:39 -07:00

38 lines
1.4 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { findMarkdownLinks, wikiCandidates } from "../../../src/lib/workspace/markdownLinks.ts";
test("markdown links skip image embeds", () => {
const links = findMarkdownLinks("See [alpha](notes/a.md) and ![shot](pic.png)");
assert.deepEqual(links, [
{ kind: "md", from: 4, to: 23, label: "alpha", target: "notes/a.md" },
]);
});
test("wikilinks skip image embeds", () => {
const links = findMarkdownLinks("Go [[projects/alpha|Alpha]] and ![[screenshot.png]]");
assert.deepEqual(links, [
{
kind: "wiki",
from: 3,
to: 27,
label: "Alpha",
target: "projects/alpha",
},
]);
});
test("wikiCandidates add .md for a bare name", () => {
assert.deepEqual(wikiCandidates("alpha"), ["alpha.md", "notes/alpha.md", "alpha"]);
});
import { linkCandidates } from "../../../src/lib/workspace/markdownLinks.ts";
test("links resolve relative to notes, including parent paths and encoded spaces", () => {
assert.deepEqual(linkCandidates("notes/project/inbox.md", "../other%20note.md", "md"), ["notes/other note.md"]);
assert.deepEqual(linkCandidates("notes/inbox.md", "ideas", "wiki"), ["notes/ideas.md", "notes/ideas", "ideas.md", "ideas"]);
assert.deepEqual(linkCandidates("notes/inbox.md", "../../secret", "md"), []);
assert.deepEqual(linkCandidates("notes/inbox.md", "javascript:alert(1)", "md"), []);
});