- build.rs creates the empty browser-engine folder that tauri-build requires, so cargo test runs before the browser runtime is staged. - The Table Formulas tests skip with a reason when the package is not built. Before, the missing module failed two whole test files. - The installer test accepts CRLF checkouts and skips with a reason when the NSIS compiler is missing. - hostTodo.spec.mjs never ran because of its extension. Its two valid background tests move to appearance.spec.ts with current defaults. The third test repeated an existing export test. - Remove tsconfig.plugins.json. It checked the plugins/ folder, which moved to separate repositories in 0.1.7.
43 lines
2.8 KiB
TypeScript
43 lines
2.8 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test, { before, after } from "node:test";
|
|
import { ExternalSession } from "../src/lib/plugins/externalSession.ts";
|
|
import { existsSync } from "node:fs";
|
|
// The Table Formulas package comes from a sibling repository. Run `pnpm build:plugins` to build it.
|
|
const tableFormulasEntry = new URL("../plugin-packages/table-formulas/main.js", import.meta.url);
|
|
const tableFormulas = existsSync(tableFormulasEntry) ? await import(tableFormulasEntry.href) : undefined;
|
|
const activate = tableFormulas?.activate;
|
|
const needsTableFormulas = { skip: tableFormulas ? false : "the Table Formulas package is not built; run pnpm build:plugins" };
|
|
const session = new ExternalSession("runestone.table-formulas", {
|
|
workspace: { list: async () => [], read: async () => "", write: async () => {} },
|
|
settings: { read: async () => null, write: async () => {} },
|
|
assets: { read: async () => new Uint8Array() },
|
|
}, () => {}, () => {});
|
|
before(() => activate && session.start({ activate }));
|
|
after(() => activate && session.stop());
|
|
|
|
import { tableCellMarkdown } from "../src/lib/editor/tableCellMarkdown.ts";
|
|
import { renderMarkdownHtml, renderMarkdownSections } from "../src/lib/workspace/noteHtml.ts";
|
|
|
|
test("Markdown rendering isolates tables and preserves literal, formatted, and non-table text", needsTableFormulas, () => {
|
|
const source = "| X | Y | Result |\r\n| --- | --- | --- |\r\n| 9 | 10 | =AVERAGE(A2:B2) |\r\n\r\n| X | Y | Result |\r\n| --- | --- | --- |\r\n| 1 | 3 | =A2*B2 |\r\n";
|
|
const html = renderMarkdownHtml(source, new Map());
|
|
assert.match(html, /aria-label="=AVERAGE\(A2:B2\) → 9.5">9.5<\/span>/);
|
|
assert.match(html, /aria-label="=A2\*B2 → 3">3<\/span>/);
|
|
const sections = renderMarkdownSections(source, new Map());
|
|
assert.equal(sections.map(s => source.slice(s.start, s.end)).join(""), source);
|
|
assert.equal(sections.map(s => s.html).join(""), html);
|
|
const literal = renderMarkdownHtml("=1+2\n\n| A | B | C |\n| --- | --- | --- |\n| `=1+2` | \\=1+2 | ==highlight== |", new Map());
|
|
assert.doesNotMatch(literal, /md-table-formula/);
|
|
assert.match(literal, /<mark>highlight<\/mark>/);
|
|
const hostile = renderMarkdownHtml('| A |\n| --- |\n| ="<img src=x onerror=alert(1)>" |', new Map());
|
|
assert.doesNotMatch(hostile, /<img/);
|
|
assert.match(hostile, /#ERROR!/);
|
|
});
|
|
|
|
test("editing keeps formulas readable and code or explicit escapes literal", needsTableFormulas, () => {
|
|
const doc = (text: string, marks?: { type: string }[]) => ({ type: "doc", content: [{ type: "paragraph", content: [{ type: "text", text, marks }] }] });
|
|
assert.equal(tableCellMarkdown(doc("=SUM($B$2:C2)*50%")), "=SUM($B$2:C2)*50%");
|
|
assert.equal(tableCellMarkdown(doc("\\=1+2")), "\\=1+2");
|
|
assert.equal(tableCellMarkdown(doc("=1+2", [{ type: "code" }])), "`=1+2`");
|
|
});
|