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.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { externalLinkText, workspaceLinkText } from "../../../src/lib/editor/linkCommands.ts";
|
||||
import { linkCandidates } from "../../../src/lib/workspace/markdownLinks.ts";
|
||||
|
||||
test("external links prepare editable syntax with the cursor in the missing field", () => {
|
||||
const empty = externalLinkText("", { from: 0, to: 0 });
|
||||
assert.equal(empty.insert, "[]()");
|
||||
assert.equal(empty.anchor, 1);
|
||||
assert.equal(empty.head, 1);
|
||||
const selected = externalLinkText("before [label] after", { from: 7, to: 14 });
|
||||
assert.equal(selected.insert, "[\\[label\\]]()");
|
||||
assert.equal(selected.anchor - selected.from, selected.insert.length - 1);
|
||||
assert.equal(selected.anchor, selected.head);
|
||||
});
|
||||
|
||||
test("workspace links retain the selected label and the exact workspace path", () => {
|
||||
assert.equal(workspaceLinkText("", { from: 0, to: 0 }, "notes/Same name.md").insert, "[[/notes/Same%20name.md]]");
|
||||
const edit = workspaceLinkText("before visible\nlabel after", { from: 7, to: 20 }, "nested/target.md");
|
||||
assert.equal(edit.insert, "[[/nested/target.md|visible label]]");
|
||||
assert.equal(edit.anchor, 7);
|
||||
assert.equal(edit.head, 7 + edit.insert.length);
|
||||
});
|
||||
|
||||
test("workspace link paths preserve spaces, brackets, hashes and literal percent signs", () => {
|
||||
const path = "notes/Nested/[A] #50%.md";
|
||||
const edit = workspaceLinkText("", { from: 0, to: 0 }, path);
|
||||
const target = edit.insert.slice(2, -2);
|
||||
assert.equal(target, "/notes/Nested/%5BA%5D%20%2350%25.md");
|
||||
assert.deepEqual(linkCandidates("notes/current.md", target, "wiki"), [path]);
|
||||
});
|
||||
Reference in New Issue
Block a user