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:
Knotty Wyvern
2026-10-27 19:47:39 -07:00
parent 90d1940c73
commit e433bed28e
154 changed files with 269 additions and 227 deletions
+129
View File
@@ -0,0 +1,129 @@
import { createRequire } from "node:module";
import assert from "node:assert/strict";
import { mkdir } from "node:fs/promises";
const require = createRequire(import.meta.url);
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
const context = await browser.newContext({ viewport: { width: 1440, height: 900 } });
await context.addInitScript(() => {
window.isTauri = true;
localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false }));
const root = location.search.includes("other") ? "C:\\other" : "C:\\transfer";
let sequence = 0;
window.__TAURI_INTERNALS__ = {
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
transformCallback: () => ++sequence, unregisterCallback: () => {},
invoke: async (command, args = {}) => {
if (command === "plugin:event|listen") return ++sequence;
if (command === "plugin:event|unlisten" || command.startsWith("plugin:window|")) return;
if (command === "workspace_last_path") return root;
if (command === "workspace_open") return { root, name: "transfer", watch_mode: "native" };
if (command === "workspace_read") return "# " + args.rel + "\n\nOriginal text.\n";
if (command === "workspace_list") return args.rel ? [] : ["a.md", "b.md"].map(name => ({ name, rel_path: name, kind: "file" }));
if (command === "workspace_search") return [];
if (command === "plugins_snapshot") return { root, plugins: [] };
throw new Error(`Unhandled IPC: ${command}`);
},
};
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
});
const url = process.env.SMOKE_URL || "http://127.0.0.1:1420";
const source = await context.newPage(), target = await context.newPage(), other = await context.newPage();
for (const page of [source, target, other]) page.setDefaultTimeout(10000);
const errors = [];
for (const page of [source, target, other]) page.on("pageerror", error => errors.push(error.message));
const tab = (page, name) => page.locator('[role="tab"]').filter({ hasText: name });
async function open(page, name) {
await page.bringToFront();
await page.getByRole("tablist", { name: "Working tabs" }).waitFor();
await page.getByRole("tab").first().waitFor();
await page.keyboard.press("Control+p");
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
await tab(page, name).waitFor();
}
async function start(page, name) {
return tab(page, name).evaluate(node => {
const transfer = new DataTransfer();
node.dispatchEvent(new DragEvent("dragstart", { bubbles: true, dataTransfer: transfer }));
return transfer.getData("application/x-runestone-tab");
});
}
async function drop(page, data) {
await page.getByRole("tablist", { name: "Working tabs" }).evaluate((node, data) => {
const transfer = new DataTransfer();
transfer.setData("application/x-runestone-tab", data);
node.dispatchEvent(new DragEvent("dragover", { bubbles: true, cancelable: true, clientX: node.getBoundingClientRect().left, dataTransfer: transfer }));
node.dispatchEvent(new DragEvent("drop", { bubbles: true, cancelable: true, clientX: node.getBoundingClientRect().left, dataTransfer: transfer }));
}, data);
}
async function captureTransfer(page, data) {
await mkdir("output/tab-transfer", { recursive: true });
for (const theme of ["light", "dark"]) {
await page.evaluate(async mode => {
const { applyAppearance } = await import('/src/lib/theme/appearance.ts');
await applyAppearance({ theme: 'default', mode });
}, theme);
await page.getByRole("tablist", { name: "Working tabs" }).evaluate((node, data) => {
const transfer = new DataTransfer();
transfer.setData("application/x-runestone-tab", data);
node.dispatchEvent(new DragEvent("dragover", { bubbles: true, cancelable: true, clientX: node.getBoundingClientRect().left, dataTransfer: transfer }));
}, data);
await page.screenshot({ path: `output/tab-transfer/${theme}-receiving.png` });
}
}
try {
await Promise.all([source.goto(url), target.goto(url), other.goto(url + "/?other")]);
await open(source, "a.md");
await open(target, "b.md");
await tab(source, "a.md").click({ button: "right" });
await source.getByRole("menuitem", { name: "Pin", exact: true }).click();
await source.locator(".cm-content").fill("Unsaved transfer text");
let data = await start(source, "a.md");
assert.ok(JSON.parse(data).tabTransfer);
await drop(other, data);
await other.getByText("Move tabs only between windows of the same workspace.").waitFor();
assert.equal(await tab(source, "a.md").count(), 1);
await captureTransfer(target, data);
await drop(target, data);
console.log("Dropped into matching workspace");
await tab(target, "a.md").waitFor();
await tab(source, "a.md").waitFor({ state: "detached" });
console.log("Source acknowledged transfer");
assert.match(await target.locator(".cm-content").innerText(), /Unsaved transfer text/);
const changedTarget = await context.newPage();
changedTarget.on("pageerror", error => errors.push(error.message));
await changedTarget.goto(url);
await changedTarget.getByRole("tab").first().waitFor();
await open(source, "a.md");
data = await start(source, "a.md");
await source.locator(".cm-content").fill("Changed during transfer");
await drop(changedTarget, data);
await tab(changedTarget, "a.md").waitFor();
assert.equal(await tab(source, "a.md").count(), 1);
assert.match(await source.locator(".cm-content").innerText(), /Changed during transfer/);
assert.ok(await tab(target, "a.md").getAttribute("aria-describedby"));
assert.deepEqual(await target.getByRole("tablist", { name: "Working tabs" }).getByRole("tab").evaluateAll(nodes => nodes.map(node => node.dataset.path)), ["a.md", "b.md"]);
await open(source, "a.md");
data = await start(source, "a.md");
await drop(target, data);
await target.getByText("This tab is already open in this window. The source tab remains open.").waitFor();
assert.equal(await tab(source, "a.md").count(), 1);
assert.match(await target.locator(".cm-content").innerText(), /Unsaved transfer text/);
await mkdir("output/tab-transfer", { recursive: true });
for (const theme of ["light", "dark"]) {
await target.evaluate(async mode => {
const { applyAppearance } = await import('/src/lib/theme/appearance.ts');
await applyAppearance({ theme: 'default', mode });
}, theme);
await target.screenshot({ path: `output/tab-transfer/${theme}.png` });
}
await target.setViewportSize({ width: 700, height: 700 });
await target.screenshot({ path: "output/tab-transfer/narrow.png" });
assert.deepEqual(errors, []);
console.log("PASS: same-workspace transfer, unsaved text, pinned state, insertion order, other-workspace rejection, duplicate protection, and source edits during transfer");
} catch (reason) {
console.log(await other.locator("body").innerText());
console.log(await target.locator("body").innerText());
throw reason;
} finally { await browser.close(); }