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
@@ -0,0 +1,145 @@
// Run against pnpm dev; use PLAYWRIGHT_MODULE for a shared Playwright installation.
import { createRequire } from "node:module";
import assert from "node:assert/strict";
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 page = await browser.newPage({ viewport: { width: 1100, height: 800 } });
const errors = [];
page.on("pageerror", err => errors.push(err.message));
await page.addInitScript(() => {
window.isTauri = true;
let current = "D:\\Notes";
let recent = ["D:\\Writing\\Notes", current, "D:\\Missing"];
let picked = null;
let contents = "Original note";
const calls = [];
const windows = [];
window.__TAURI_INTERNALS__ = {
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
transformCallback: () => 1, unregisterCallback: () => {},
invoke: async (command, args = {}) => {
calls.push({ command, args });
if (command === "workspace_last_path") return current;
if (command === "workspace_recent") return recent;
if (command === "workspace_forget") { recent = recent.filter(path => path !== args.path); return recent; }
if (command === "workspace_list") return args.rel ? [] : [{ name: "note.txt", rel_path: "note.txt", kind: "file" }];
if (command === "workspace_read") { if (args.rel === "note.txt") return contents; throw "File not found"; }
if (command === "workspace_write") { contents = args.contents; return; }
if (command === "pty_profiles") return [{ id: "powershell", title: "PowerShell", kind: "powershell" }];
if (command === "plugin:dialog|open") return picked;
if (command === "plugin:dialog|message") return "Cancel";
if (command === "workspace_new") {
if (args.name === "Existing") throw "A file or folder with that name already exists.";
const root = args.parent + "\\" + args.name;
recent = [root, ...recent]; windows.push(root);
return;
}
if (command === "workspace_open_window") {
if (args.path.endsWith("Missing")) throw "folder does not exist";
windows.push(args.path);
recent = [args.path, ...recent.filter(p => p !== args.path)];
return;
}
if (command === "workspace_open") {
if (args.path.endsWith("Missing")) throw "folder does not exist";
current = args.path; recent = [current, ...recent.filter(p => p !== current)];
return { root: current, name: current.split("\\").pop(), watch_mode: "native" };
}
return null;
},
};
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
window.__TEST__ = { calls, windows, pick: path => picked = path, clear: () => recent = [], reorder: () => recent = ["D:\\Writing\\Notes", current, "D:\\Missing"] };
});
try {
await page.goto(process.env.SMOKE_URL || "http://127.0.0.1:1420");
await page.locator(".ws").filter({ hasText: "Notes" }).waitFor();
await page.keyboard.press("Control+p");
await page.getByRole("textbox", { name: "Find a file" }).fill("note.txt");
await page.getByRole("dialog").getByRole("button").filter({ hasText: "note.txt" }).first().click();
await page.locator(".monaco-editor textarea").waitFor();
await page.evaluate(async () => {
window.__MONACO__ = (await import("/src/lib/editor/monacoEnv.ts")).monaco;
window.__MONACO__.editor.getEditors().find(e => e.getDomNode()?.isConnected).setValue("My pending edit");
});
const trigger = page.getByRole("button", { name: "Open folder", exact: true });
const menu = page.getByRole("dialog", { name: "Workspaces", exact: true });
await page.evaluate(() => window.__TEST__.reorder());
await trigger.click();
await menu.getByText("D:\\Writing\\Notes", { exact: true }).waitFor();
await page.mouse.move(1000, 50);
assert.equal(await menu.locator('.workspace-row').first().evaluate(node => node === document.activeElement), false, "Pointer opening does not force focus onto a different workspace");
assert.equal(await menu.locator('.workspace-row').first().evaluate(node => getComputedStyle(node).backgroundColor), "rgba(0, 0, 0, 0)", "The first workspace has no stuck highlight");
assert.equal(await menu.locator('[aria-current="true"]').count(), 1);
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "plugin:dialog|open").length), 0);
await page.screenshot({ path: ".audit/workspaces-menu.png" });
const opened = await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "workspace_open").length);
await menu.getByRole("button").filter({ hasText: "Current" }).click();
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "workspace_open").length), opened);
await page.keyboard.press("Control+o");
await menu.getByRole("button").filter({ hasText: "Missing" }).click();
await menu.getByRole("alert").filter({ hasText: "folder does not exist" }).waitFor();
await menu.getByRole("button", { name: "Open another folder…" }).click();
assert(await menu.isVisible(), "Cancelling folder picker keeps history available");
await menu.getByRole("button").filter({ hasText: "D:\\Writing\\Notes" }).click();
await menu.waitFor({ state: "hidden" });
assert.equal(await page.locator(".ws").textContent(), "Notes");
assert.deepEqual(await page.evaluate(() => window.__TEST__.windows), ["D:\\Writing\\Notes"]);
await trigger.click();
await page.evaluate(() => window.__TEST__.pick("D:\\Other"));
await menu.getByRole("button", { name: "Open another folder…" }).click();
await menu.waitFor({ state: "hidden" });
assert.equal(await page.locator(".ws").textContent(), "Notes");
await trigger.click();
await menu.getByRole("button", { name: "New workspace…" }).click();
const dialog = page.getByRole("dialog", { name: "New workspace", exact: true });
assert(await dialog.getByRole("button", { name: "Create workspace", exact: true }).isDisabled());
await dialog.getByLabel("Workspace name").fill("Existing");
await page.evaluate(() => window.__TEST__.pick("D:\\Projects"));
await dialog.getByRole("button", { name: "Browse…" }).click();
await dialog.getByRole("button", { name: "Create workspace", exact: true }).click();
await dialog.getByRole("alert").filter({ hasText: "already exists" }).waitFor();
await dialog.getByLabel("Workspace name").fill("Fresh notes");
await page.screenshot({ path: ".audit/workspaces-create.png" });
await dialog.getByRole("button", { name: "Create workspace", exact: true }).click();
await dialog.waitFor({ state: "hidden" });
assert.equal(await page.locator(".ws").textContent(), "Notes");
assert.deepEqual(await page.evaluate(() => window.__TEST__.windows), ["D:\\Writing\\Notes", "D:\\Other", "D:\\Projects\\Fresh notes"]);
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "workspace_open").length), opened);
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "plugin:dialog|message").length), 0);
assert.equal(await page.evaluate(() => window.__MONACO__.editor.getEditors().find(e => e.getDomNode()?.isConnected)?.getValue()), "My pending edit");
assert(await page.getByRole("tab", { name: /note\.txt/ }).isVisible());
await trigger.click();
await page.keyboard.press("End");
assert.equal(await page.locator(":focus").textContent(), " Open another folder…");
await page.keyboard.press("Escape");
await menu.waitFor({ state: "hidden" });
for (const theme of ['light', 'dark']) {
await page.evaluate(async mode => {
const { applyAppearance } = await import('/src/lib/theme/appearance.ts');
applyAppearance({ theme: 'default', mode });
}, theme);
await page.setViewportSize({ width: theme === 'light' ? 1100 : 380, height: 800 });
await trigger.click();
await menu.getByRole('button', { name: 'Remove D:\\Missing from recent workspaces', exact: true }).focus();
await page.screenshot({ path: `.audit/workspaces-remove-${theme}.png` });
if (theme === 'dark') {
await page.keyboard.press('Enter');
await menu.getByText('D:\\Missing', { exact: true }).waitFor({ state: 'detached' });
assert.equal(await page.locator('.ws').textContent(), 'Notes', 'History removal does not close the current workspace');
await page.keyboard.press('Escape');
await trigger.click();
assert.equal(await menu.getByText('D:\\Missing', { exact: true }).count(), 0, 'Removed paths stay absent after reopening');
}
await page.keyboard.press('Escape');
}
await page.setViewportSize({ width: 1100, height: 800 });
await page.evaluate(() => window.__TEST__.clear());
await trigger.click();
await menu.getByText("No recent workspaces yet.").waitFor();
await page.getByRole("button", { name: "New tab (Ctrl T)", exact: true }).click();
await menu.waitFor({ state: "hidden" });
assert.deepEqual(errors, []);
console.log("Workspace smoke passed: history, opening and creating in new windows, original workspace preserved, cancellation, errors, keyboard and empty state.");
} finally { await browser.close(); }