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.
24 lines
1.3 KiB
TypeScript
24 lines
1.3 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { SearchQuery } from "@codemirror/search";
|
|
import { documentMatches, replacementText } from "../../../src/lib/editor/findTarget.ts";
|
|
|
|
test("document search uses Writer word matching and normalized CRLF positions", () => {
|
|
const query = new SearchQuery({ search: "Alpha", wholeWord: true, caseSensitive: true });
|
|
const { state, matches } = documentMatches("Alpha alphabet\r\nalpha Alpha", query);
|
|
assert.deepEqual(matches.map(({ from, to }) => ({ from, to })), [{ from: 0, to: 5 }, { from: 21, to: 26 }]);
|
|
assert.equal(state.doc.lineAt(matches[1].from).number, 2);
|
|
assert.equal(state.doc.lineAt(matches[1].from).from, 15);
|
|
});
|
|
|
|
test("replacement keeps regex context, capture groups, dollars, and line breaks", () => {
|
|
const query = new SearchQuery({ search: "(?<=G)(amma)", regexp: true, replace: "$1-$12-$&-$$\\n" });
|
|
assert.equal(replacementText("Gamma", 1, query), "amma-amma2-amma-$\n");
|
|
assert.equal(replacementText("Alpha", 0, new SearchQuery({ search: "Alpha", replace: "$1\\t" })), "$1\t");
|
|
});
|
|
|
|
test("empty and invalid queries do not produce matches", () => {
|
|
assert.deepEqual(documentMatches("Alpha", new SearchQuery({ search: "" })).matches, []);
|
|
assert.deepEqual(documentMatches("Alpha", new SearchQuery({ search: "[", regexp: true })).matches, []);
|
|
});
|