Move the smoke tests onto the shared harness

Each smoke test now uses tests/smoke/_harness/ for Playwright, the Tauri
IPC mock, the in-memory workspace, and output folders, instead of its
own copy. The tests keep their interactions and assertions. Mock
handlers that the app never calls are gone.

- Split the four mixed regression scripts into 18 feature tests.
- Update tests that broke when the app changed on purpose. Each update
  cites the app source that shows the new behavior.
- Mark two real app defects with @known-issue: the settings window
  controls are 1px shorter than the main window controls, and plugin
  tabs cannot be reordered by dragging without a workspace.
- Merge three palette unit tests into one table-driven test.
- The native tests load Playwright through the harness and read
  NATIVE_CDP_URL, with their old variable names as fallbacks.
- A failed smoke test saves a screenshot and prints the console errors.
- The runner runs failed tests once more, alone, and reports a test
  that then passes as flaky.

Result: 89 passed, 1 flaky, 2 known issues, 0 failed. Before, 45 of 78
passed.
This commit is contained in:
Knotty Wyvern
2026-10-27 20:58:55 -07:00
parent c66ea1ce83
commit 69f90df571
109 changed files with 5920 additions and 7915 deletions
@@ -0,0 +1,26 @@
// An outside click closes the New file dialog and Find file; a click inside Find file keeps it open.
import assert from "node:assert/strict";
import { mockTauri, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("workspace/dialogDismissal", async ({ page }) => {
await mockTauri(page, {
commands: test => ({
...test.workspace({ root: "C:\\dialog-dismissal", files: { "a.md": "# Note\n\nOriginal text." } }),
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
spelling_menu_install: () => null,
}),
});
await page.goto(smokeUrl);
await page.locator('[data-tree-rel="a.md"]').waitFor();
await page.getByRole("button", { name: "New file Ctrl N" }).click();
await page.getByRole("textbox", { name: "New file path relative to the workspace" }).waitFor();
await page.mouse.click(5, 700);
assert.equal(await page.locator("dialog").count(), 0, "Outside click dismisses new-file dialog");
// The empty tab's button is now "Find file" (src/lib/layout/EditorPane.svelte:167).
await page.getByRole("button", { name: "Find file Ctrl P" }).click();
await page.getByRole("textbox", { name: "Find a file" }).click();
assert.equal(await page.locator("dialog").count(), 1, "Inside click keeps file search open");
await page.mouse.click(5, 700);
assert.equal(await page.locator("dialog").count(), 0, "Outside click dismisses file search");
console.log("PASS: outside clicks dismiss the New file dialog and Find file");
}, { viewport: { width: 1200, height: 850 } });
@@ -0,0 +1,80 @@
// Note templates from the file pane menu: New note from a template, and the template manager's rename, name conflict, edit, new, delete, and long list.
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
const name = "workspace/manageTemplates";
await runSmoke(name, async ({ page }) => {
const output = await outputDir(name);
await mockTauri(page, {
commands: test => {
const workspace = test.workspace({ root: "C:\\manage-templates", files: { "a.md": "# Note\n\nOriginal text.", ".runestone/templates/Daily.md": "# Daily\n\n## Tasks" } });
test.files = workspace.files;
return {
...workspace,
workspace_list: args => workspace.workspace_list(args).filter(entry => args.rel || entry.rel_path !== ".runestone"),
"plugin:dialog|message": () => "Ok",
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
spelling_menu_install: () => null,
};
},
});
const row = path => page.locator(`[data-tree-rel="${path}"]`);
const item = name => page.getByRole("menuitem", { name, exact: true });
const button = name => page.getByRole("button", { name, exact: true });
const templateName = () => page.getByRole("textbox", { name: "Template name", exact: true });
const file = path => page.evaluate(path => window.__TEST__.files.get(path), path);
async function openManager() {
await page.getByRole("navigation", { name: "Workspace files" }).click({ button: "right", position: { x: 90, y: 360 } });
await item("New note").hover();
await item("Manage templates…").click();
}
await page.goto(smokeUrl);
await row("a.md").waitFor();
await page.getByRole("navigation", { name: "Workspace files" }).click({ button: "right", position: { x: 90, y: 360 } });
await item("New note").hover();
await item("Daily").click();
await row("Daily.md").waitFor();
assert.equal(await file("Daily.md"), "# Daily\n\n## Tasks");
console.log("PASS: New note from a template");
await openManager();
await button("Rename Daily").click();
await templateName().fill("Weekly");
await button("Continue").click();
await button("Edit Weekly").waitFor();
await page.evaluate(() => window.__TEST__.files.set(".runestone/templates/Existing.md", "# Keep this template"));
await button("Rename Weekly").click();
await templateName().fill("Existing");
await button("Continue").click();
await page.getByRole("alert").filter({ hasText: "Destination exists" }).waitFor();
assert.equal(await file(".runestone/templates/Existing.md"), "# Keep this template");
for (const mode of ["light", "dark"]) {
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); }, mode);
await page.screenshot({ path: path.join(output, `templates-${mode}.png`) });
}
await button("Edit Weekly").click();
await page.getByRole("tab", { name: "Weekly.md", exact: true }).waitFor();
console.log("PASS: rename, rename conflict, and edit a template");
await openManager();
await button("New template").click();
await templateName().fill("Meeting");
await button("Continue").click();
await page.getByRole("tab", { name: "Meeting.md", exact: true }).waitFor();
assert.equal(await file(".runestone/templates/Meeting.md"), "");
await openManager();
await button("Delete Weekly").click();
await button("Edit Weekly").waitFor({ state: "detached" });
assert.equal(await file("Daily.md"), "# Daily\n\n## Tasks", "Deleting template preserves notes");
await button("Close templates").click();
console.log("PASS: create and delete a template");
await page.evaluate(() => { for (let i = 0; i < 40; i++) window.__TEST__.files.set(`.runestone/templates/Long template name ${i}.md`, "# Template"); });
await page.setViewportSize({ width: 600, height: 600 });
await openManager();
assert.ok(await page.locator("dialog .list").evaluate(node => node.scrollHeight > node.clientHeight), "Long template list scrolls");
await page.screenshot({ path: path.join(output, "templates-narrow-long.png") });
await button("Close templates").click();
console.log("PASS: a long template list scrolls in a narrow window");
}, { viewport: { width: 1200, height: 850 } });
+47 -59
View File
@@ -1,59 +1,48 @@
// Run against pnpm dev; use PLAYWRIGHT_MODULE for a shared Playwright installation.
import { createRequire } from "node:module";
// Workspace menu: recent history, opening and creating workspaces in new windows, cancellation, errors, keyboard use, removal, and the empty state.
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;
import path from "node:path";
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("workspace/openAndCreate", async ({ page }) => {
const output = await outputDir("workspace/openAndCreate");
// Unknown commands return null, as the original mock did.
await mockTauri(page, {
strict: false,
commands: test => {
let current = "D:\\Notes";
let recent = ["D:\\Writing\\Notes", current, "D:\\Missing"];
let picked = null;
let contents = "Original note";
const windows = [];
Object.assign(test, { windows, pick: path => picked = path, clear: () => recent = [], reorder: () => recent = ["D:\\Writing\\Notes", current, "D:\\Missing"] });
return {
workspace_last_path: () => current,
workspace_recent: () => recent,
workspace_forget: args => { recent = recent.filter(path => path !== args.path); return recent; },
workspace_list: args => args.rel ? [] : [{ name: "note.txt", rel_path: "note.txt", kind: "file" }],
workspace_read: args => { if (args.rel === "note.txt") return contents; throw "File not found"; },
workspace_write: args => { contents = args.contents; },
"plugin:dialog|open": () => picked,
"plugin:dialog|message": () => "Cancel",
workspace_new: args => {
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);
},
workspace_open_window: args => {
if (args.path.endsWith("Missing")) throw "folder does not exist";
windows.push(args.path);
recent = [args.path, ...recent.filter(p => p !== args.path)];
},
workspace_open: args => {
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" };
},
};
},
};
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.goto(smokeUrl);
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");
@@ -73,7 +62,7 @@ try {
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" });
await page.screenshot({ path: path.join(output, "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);
@@ -101,7 +90,7 @@ try {
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 page.screenshot({ path: path.join(output, "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");
@@ -123,7 +112,7 @@ try {
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` });
await page.screenshot({ path: path.join(output, `workspaces-remove-${theme}.png`) });
if (theme === 'dark') {
await page.keyboard.press('Enter');
await menu.getByText('D:\\Missing', { exact: true }).waitFor({ state: 'detached' });
@@ -140,6 +129,5 @@ try {
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(); }
}, { viewport: { width: 1100, height: 800 }, timeout: 30000 });
@@ -0,0 +1,35 @@
// Save a note as a template from the file tree, then create a note from it with the empty tab's New note button.
import assert from "node:assert/strict";
import { mockTauri, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("workspace/saveAsTemplate", async ({ page }) => {
await mockTauri(page, {
commands: test => {
const workspace = test.workspace({ root: "C:\\save-template", files: { "a.md": "# Alpha\n\nTemplate body.\n", "b.md": "# Beta\n", ".runestone/config.json": "{}" } });
test.files = workspace.files;
return {
...workspace,
workspace_list: args => workspace.workspace_list(args).filter(entry => args.rel || args.showInternal || entry.rel_path !== ".runestone"),
plugins_snapshot: () => ({ plugins: [], issues: [] }),
spelling_menu_install: () => null,
};
},
});
const row = path => page.locator(`[data-tree-rel="${path}"]`);
const menu = label => page.getByRole("menuitem", { name: label, exact: true });
await page.goto(smokeUrl);
await row("a.md").click();
await page.locator(".cm-content").waitFor();
await row("a.md").click({ button: "right" });
await menu("Save as template").click();
await page.getByRole("textbox", { name: "Template name" }).fill("Meeting");
await page.getByRole("button", { name: "Continue", exact: true }).click();
await page.waitForFunction(() => window.__TEST__.files.has(".runestone/templates/Meeting.md"));
await page.getByRole("button", { name: "New tab (Ctrl T)", exact: true }).click();
// The file tree toolbar also has a "New note" button (src/lib/layout/FileTree.svelte:886); this one is in the empty tab (src/lib/layout/EditorPane.svelte:166).
await page.getByRole("main").getByRole("button", { name: "New note", exact: true }).click();
await menu("Meeting").click();
await page.getByRole("tab", { name: /Meeting/ }).waitFor();
assert.equal(await page.evaluate(() => window.__TEST__.files.get("Meeting.md")), "# Alpha\n\nTemplate body.\n");
console.log("PASS: Save as template, and New note from the saved template");
}, { timeout: 15000 });