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:
@@ -1,134 +1,73 @@
|
||||
// Table keyboard navigation: arrows, caret positions, entry and exit in all directions, goal columns, line breaks, stable cell sizes, saving, and undo.
|
||||
// @requires plugin:terminal plugin:table-formulas
|
||||
import { mockFeaturePlugins } from "../_harness/pluginMocks.mjs";
|
||||
// Run against `pnpm dev`. PLAYWRIGHT_MODULE may point to a shared 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: 1440, height: 1000 } });
|
||||
page.setDefaultTimeout(10000);
|
||||
const errors = [];
|
||||
page.on("console", message => { if (message.type() === "error" || message.type() === "warning") console.log(message.type(), message.text()); });
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
await page.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const root = "C:\\smoke-workspace";
|
||||
const files = new Map([
|
||||
["notes/welcome.md", "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n"],
|
||||
["notes/second.md", "# Second note\n"],
|
||||
["src/hello.py", "print('hello')\n"],
|
||||
]);
|
||||
const callbacks = new Map();
|
||||
const listeners = new Map();
|
||||
let sequence = 0;
|
||||
const calls = [];
|
||||
const emit = (event, payload) => {
|
||||
for (const id of listeners.get(event) || []) callbacks.get(id)?.({ event, id, payload });
|
||||
};
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
||||
transformCallback: callback => { const id = ++sequence; callbacks.set(id, callback); return id; },
|
||||
unregisterCallback: id => callbacks.delete(id),
|
||||
invoke: async (command, args = {}) => {
|
||||
calls.push({ command, args });
|
||||
if (command === "plugin:event|listen") {
|
||||
const list = listeners.get(args.event) || []; list.push(args.handler); listeners.set(args.event, list); return args.handler;
|
||||
}
|
||||
if (command === "plugin:event|unlisten") { callbacks.delete(args.eventId); return; }
|
||||
if (command === "workspace_last_path") return root;
|
||||
if (command === "workspace_open") return { root, name: "smoke-workspace", watch_mode: "native" };
|
||||
if (command === "workspace_read") { if (!files.has(args.rel)) throw new Error("missing"); return files.get(args.rel); }
|
||||
if (command === "workspace_write") {
|
||||
if (args.expected !== undefined && files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
|
||||
files.set(args.rel, args.contents); emit("workspace-event", { root, kind: "modify", paths: [args.rel] }); return;
|
||||
}
|
||||
if (command === "workspace_list") {
|
||||
const prefix = args.rel ? args.rel + "/" : "";
|
||||
const entries = new Map();
|
||||
for (const path of files.keys()) {
|
||||
if (!path.startsWith(prefix) || path.startsWith(".runestone/")) continue;
|
||||
const tail = path.slice(prefix.length); const name = tail.split("/")[0];
|
||||
entries.set(name, { name, rel_path: prefix + name, kind: tail.includes("/") ? "folder" : "file" });
|
||||
}
|
||||
return [...entries.values()];
|
||||
}
|
||||
if (command === "workspace_create") { if (files.has(args.rel)) throw new Error("exists"); files.set(args.rel, ""); return; }
|
||||
if (command === "workspace_search") return [];
|
||||
if (command === "pty_profiles") return [{ id: "powershell", title: "PowerShell", kind: "powershell" }];
|
||||
if (command === "pty_open") {
|
||||
const data = [...new TextEncoder().encode("READY 🪨\r\n\x1b[6n")];
|
||||
emit("pty-data", { id: args.id, data: data.slice(0, 8) });
|
||||
emit("pty-data", { id: args.id, data: data.slice(8) });
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
return;
|
||||
}
|
||||
if (command.startsWith("pty_")) return;
|
||||
if (command === "plugin:dialog|message") return "Cancel";
|
||||
throw new Error(`Unhandled IPC: ${command}`);
|
||||
import { mockTauri, runSmoke, settle, smokeUrl } from "../_harness/index.mjs";
|
||||
import { mockFeaturePlugins } from "../_harness/pluginMocks.mjs";
|
||||
|
||||
await runSmoke("tables/navigation", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const workspace = test.workspace({ root: "C:\\smoke-workspace", writeEvents: true });
|
||||
test.files = workspace.files;
|
||||
return workspace;
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: (_event, id) => callbacks.delete(id) };
|
||||
window.__TEST__ = { files, calls, emit, root };
|
||||
});
|
||||
|
||||
await mockFeaturePlugins(page);
|
||||
|
||||
async function quickOpen(name) {
|
||||
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 page.locator('.live-writer .cm-content').waitFor();
|
||||
}
|
||||
|
||||
const source = '# Navigation\n\nBefore.\n\n| Name | Value | Formula |\n| --- | --- | --- |\n| Alpha | 12 | =B2*2 |\n| Beta | | tail |\n| Two<br>lines | short | end |\n\nAfter.\n';
|
||||
const table = page.locator('.live-writer table');
|
||||
const cell = (r, c) => table.locator('tr').nth(r).locator('th, td').nth(c);
|
||||
const edit = page.locator('.writer-cell-editor');
|
||||
async function expectCell(r, c) {
|
||||
await page.waitForFunction(({ r, c }) => {
|
||||
const active = document.activeElement;
|
||||
const cell = active?.closest('th, td');
|
||||
return active?.matches('.writer-cell-editor') && cell?.cellIndex === c && cell.parentElement.rowIndex === r;
|
||||
}, { r, c });
|
||||
await page.evaluate(() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))));
|
||||
}
|
||||
async function at(r, c, edge = 'End') {
|
||||
await cell(r, c).click();
|
||||
// ProseMirror guards native selections at the start for 200ms after focus.
|
||||
await page.waitForTimeout(220);
|
||||
await page.keyboard.press(`Control+${edge}`);
|
||||
await expectCell(r, c);
|
||||
}
|
||||
async function arrow(key, r, c) {
|
||||
await page.keyboard.press(key);
|
||||
await expectCell(r, c);
|
||||
}
|
||||
async function expectProse(after) {
|
||||
await page.waitForFunction(after => {
|
||||
const content = document.querySelector('.live-writer .cm-content');
|
||||
const table = content?.querySelector('table');
|
||||
const caret = document.getSelection()?.focusNode;
|
||||
return content === document.activeElement && !content.querySelector('.writer-cell-editor') && table && caret &&
|
||||
(table.compareDocumentPosition(caret) & (after ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING));
|
||||
}, after);
|
||||
}
|
||||
async function caret() {
|
||||
return edit.evaluate(el => {
|
||||
const selection = window.getSelection();
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents(el);
|
||||
range.setEnd(selection.focusNode, selection.focusOffset);
|
||||
return { offset: range.toString().length, selected: selection.toString() };
|
||||
});
|
||||
}
|
||||
try {
|
||||
await page.goto(process.env.SMOKE_URL || 'http://127.0.0.1:1420');
|
||||
await mockFeaturePlugins(page);
|
||||
// Add a file after the workspace opens, as an external change would.
|
||||
const addFile = (name, text) => page.evaluate(({ name, text }) => {
|
||||
window.__TEST__.files.set(name, text);
|
||||
window.__TEST__.emit('workspace-event', { root: 'C:\\smoke-workspace', kind: 'create', paths: [name] });
|
||||
}, { name, text });
|
||||
async function quickOpen(name) {
|
||||
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 page.locator('.live-writer .cm-content').waitFor();
|
||||
}
|
||||
const source = '# Navigation\n\nBefore.\n\n| Name | Value | Formula |\n| --- | --- | --- |\n| Alpha | 12 | =B2*2 |\n| Beta | | tail |\n| Two<br>lines | short | end |\n\nAfter.\n';
|
||||
const table = page.locator('.live-writer table');
|
||||
const cell = (r, c) => table.locator('tr').nth(r).locator('th, td').nth(c);
|
||||
const edit = page.locator('.writer-cell-editor');
|
||||
async function expectCell(r, c) {
|
||||
await page.waitForFunction(({ r, c }) => {
|
||||
const active = document.activeElement;
|
||||
const cell = active?.closest('th, td');
|
||||
return active?.matches('.writer-cell-editor') && cell?.cellIndex === c && cell.parentElement.rowIndex === r;
|
||||
}, { r, c });
|
||||
await settle(page);
|
||||
}
|
||||
async function at(r, c, edge = 'End') {
|
||||
await cell(r, c).click();
|
||||
// ProseMirror guards native selections at the start for 200ms after focus.
|
||||
await page.waitForTimeout(220);
|
||||
await page.keyboard.press(`Control+${edge}`);
|
||||
await expectCell(r, c);
|
||||
}
|
||||
async function arrow(key, r, c) {
|
||||
await page.keyboard.press(key);
|
||||
await expectCell(r, c);
|
||||
}
|
||||
async function expectProse(after) {
|
||||
await page.waitForFunction(after => {
|
||||
const content = document.querySelector('.live-writer .cm-content');
|
||||
const table = content?.querySelector('table');
|
||||
const caret = document.getSelection()?.focusNode;
|
||||
return content === document.activeElement && !content.querySelector('.writer-cell-editor') && table && caret &&
|
||||
(table.compareDocumentPosition(caret) & (after ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING));
|
||||
}, after);
|
||||
}
|
||||
async function caret() {
|
||||
return edit.evaluate(el => {
|
||||
const selection = window.getSelection();
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents(el);
|
||||
range.setEnd(selection.focusNode, selection.focusOffset);
|
||||
return { offset: range.toString().length, selected: selection.toString() };
|
||||
});
|
||||
}
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
||||
await page.evaluate(text => {
|
||||
window.__TEST__.files.set('navigation.md', text);
|
||||
window.__TEST__.emit('workspace-event', { root: window.__TEST__.root, kind: 'create', paths: ['navigation.md'] });
|
||||
}, source);
|
||||
await addFile('navigation.md', source);
|
||||
await quickOpen('navigation.md');
|
||||
await table.waitFor();
|
||||
|
||||
@@ -307,10 +246,7 @@ try {
|
||||
await page.setViewportSize({ width, height: 1000 });
|
||||
await page.evaluate(theme => { document.documentElement.dataset.theme = theme; }, theme);
|
||||
const name = `stable-${theme}-${width}.md`;
|
||||
await page.evaluate(({ name, text }) => {
|
||||
window.__TEST__.files.set(name, text);
|
||||
window.__TEST__.emit('workspace-event', { root: window.__TEST__.root, kind: 'create', paths: [name] });
|
||||
}, { name, text: stableSource });
|
||||
await addFile(name, stableSource);
|
||||
await quickOpen(name);
|
||||
await table.waitFor();
|
||||
const initial = await dimensions();
|
||||
@@ -352,10 +288,7 @@ try {
|
||||
// A line break in a tall table keeps the caret and viewport in the active cell.
|
||||
const tallSource = '# Tall table\n\nBefore.\n\n| Name | Value |\n| --- | --- |\n' +
|
||||
Array.from({ length: 45 }, (_, i) => `| Row ${i + 1} | |`).join('\n') + '\n\nAfter.\n';
|
||||
await page.evaluate(text => {
|
||||
window.__TEST__.files.set('line-breaks.md', text);
|
||||
window.__TEST__.emit('workspace-event', { root: window.__TEST__.root, kind: 'create', paths: ['line-breaks.md'] });
|
||||
}, tallSource);
|
||||
await addFile('line-breaks.md', tallSource);
|
||||
await quickOpen('line-breaks.md');
|
||||
await table.waitFor();
|
||||
for (const [r, c, key] of [[1, 0, 'Shift+Enter'], [20, 0, 'Shift+Enter'], [21, 0, 'Shift+Enter'], [20, 0, 'Shift+Enter'], [20, 1, 'Shift+Enter'], [0, 0, 'Shift+Enter']]) {
|
||||
@@ -383,10 +316,7 @@ try {
|
||||
const loneTable = '| Name |\n| --- |\n| Value |';
|
||||
for (const [key, after] of [['ArrowLeft', false], ['ArrowUp', false], ['ArrowRight', true], ['ArrowDown', true]]) {
|
||||
const name = `${key}.md`;
|
||||
await page.evaluate(({ name, text }) => {
|
||||
window.__TEST__.files.set(name, text);
|
||||
window.__TEST__.emit('workspace-event', { root: window.__TEST__.root, kind: 'create', paths: [name] });
|
||||
}, { name, text: loneTable });
|
||||
await addFile(name, loneTable);
|
||||
await quickOpen(name);
|
||||
await table.waitFor();
|
||||
await at(after ? 1 : 0, 0, after ? 'End' : 'Home');
|
||||
@@ -404,9 +334,4 @@ try {
|
||||
const expected = after ? `${loneTable}\n\nOutside.` : `\nOutside.\n${loneTable}`;
|
||||
await page.waitForFunction(({ name, expected }) => window.__TEST__.files.get(name) === expected, { name, expected });
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
console.log('PASS: arrows, caret positions, row wrapping, empty/formula/header cells, entry/exit in all directions, goal columns, document boundaries, text selection, word movement, multiline/wrapped text, line breaks and scrolling in tall tables, save, undo/redo, Tab and Escape, stable cell dimensions and table/prose boundaries in both themes at wide/narrow widths');
|
||||
} catch (error) {
|
||||
await page.screenshot({ path: '.audit/table-navigation-failure.png' });
|
||||
throw error;
|
||||
} finally { await browser.close(); }
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user