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,105 +1,61 @@
|
||||
// Table formulas: live recalculation, raw formula editing, Enter and Tab, undo, cycles, saving, the footer layout, and the Read and Split views.
|
||||
// @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}`);
|
||||
},
|
||||
};
|
||||
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').waitFor();
|
||||
await page.keyboard.press('Control+e');
|
||||
await page.locator(".monaco-editor textarea").waitFor();
|
||||
}
|
||||
import path from "node:path";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
import { mockFeaturePlugins } from "../_harness/pluginMocks.mjs";
|
||||
|
||||
const source = '# Table formulas\n\n| Name | Appearance | Charisma | Combined |\n| --- | ---: | ---: | ---: |\n| First | 9 | 10 | =AVERAGE(B2:C2) |\n| Second | 7 | 9 | =SUM(B3+C3)/2 |\n| Total | | | =SUM(D2:D3) |\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');
|
||||
const result = (r, c) => cell(r, c).locator('.md-table-formula');
|
||||
async function save() {
|
||||
await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(() => !document.querySelector('[aria-label^="Save changes"]'));
|
||||
return page.evaluate(() => window.__TEST__.files.get('formulas.md'));
|
||||
}
|
||||
try {
|
||||
await page.goto(process.env.SMOKE_URL || 'http://127.0.0.1:1420');
|
||||
|
||||
await runSmoke("tables/formulas", async ({ page }) => {
|
||||
const output = await outputDir("tables/formulas");
|
||||
await mockTauri(page, {
|
||||
state: { files: { 'formulas.md': source } },
|
||||
commands: test => {
|
||||
const workspace = test.workspace({ root: "C:\\smoke-workspace", files: test.state.files, writeEvents: true });
|
||||
test.files = workspace.files;
|
||||
return workspace;
|
||||
},
|
||||
});
|
||||
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').waitFor();
|
||||
await page.keyboard.press('Control+e');
|
||||
await page.locator(".monaco-editor textarea").waitFor();
|
||||
}
|
||||
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');
|
||||
const result = (r, c) => cell(r, c).locator('.md-table-formula');
|
||||
const shot = name => page.screenshot({ path: path.join(output, `${name}.png`) });
|
||||
async function save() {
|
||||
await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(() => !document.querySelector('[aria-label^="Save changes"]'));
|
||||
return page.evaluate(() => window.__TEST__.files.get('formulas.md'));
|
||||
}
|
||||
// Footer controls share one normal-flow block aligned to the table at any width.
|
||||
async function checkFooter() {
|
||||
const geometry = await page.evaluate(() => {
|
||||
const rect = selector => document.querySelector(selector).getBoundingClientRect().toJSON();
|
||||
return { table: rect('.live-writer .md-table-scroll'), footer: rect('.table-footer'), tools: rect('.table-formula-tools'), help: rect('.table-edit-help'), helpHidden: document.querySelector('.table-edit-help').hidden, summary: rect('.table-formula-help summary'), status: rect('.table-formula-status') };
|
||||
});
|
||||
assert.ok(Math.abs(geometry.table.x - geometry.footer.x) < 2);
|
||||
assert.ok(Math.abs(geometry.footer.x - geometry.tools.x) < 2);
|
||||
if (!geometry.helpHidden) assert.ok(Math.abs(geometry.help.x - geometry.tools.x) < 2);
|
||||
assert.ok(geometry.footer.y >= geometry.table.bottom);
|
||||
assert.ok(geometry.footer.y - geometry.table.bottom <= 28, 'Only the add-row control sits between table and footer');
|
||||
if (!geometry.helpHidden) {
|
||||
assert.ok(geometry.tools.y >= geometry.help.bottom, 'Help must not overlap the controls');
|
||||
assert.ok(geometry.help.right <= geometry.footer.right + 1);
|
||||
}
|
||||
if (geometry.status.x > geometry.summary.right) assert.ok(Math.abs((geometry.status.y + geometry.status.height / 2) - (geometry.summary.y + geometry.summary.height / 2)) < 2);
|
||||
}
|
||||
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText('smoke-workspace', { exact: true }).waitFor();
|
||||
await page.evaluate(text => {
|
||||
window.__TEST__.files.set('formulas.md', text);
|
||||
window.__TEST__.emit('workspace-event', { root: window.__TEST__.root, kind: 'create', paths: ['formulas.md'] });
|
||||
}, source);
|
||||
await quickOpen('formulas.md');
|
||||
await page.keyboard.press('Control+e');
|
||||
await table.waitFor();
|
||||
@@ -109,7 +65,7 @@ try {
|
||||
await page.locator('.rs-tooltip:popover-open').waitFor();
|
||||
assert.equal(await cell(1, 3).getAttribute('title'), null);
|
||||
assert.match(await page.locator('.rs-tooltip:popover-open').innerText(), /D2.*AVERAGE/);
|
||||
await page.screenshot({ path: '.audit/table-cell-hint.png' });
|
||||
await shot('cell-hint');
|
||||
await page.keyboard.press('Escape');
|
||||
assert.equal(await page.locator('.rs-tooltip:popover-open').count(), 0);
|
||||
await cell(1, 3).click();
|
||||
@@ -144,7 +100,8 @@ try {
|
||||
assert.equal(await result(3, 3).innerText(), '58');
|
||||
await cell(2, 3).click();
|
||||
await edit.fill('=D3');
|
||||
await page.keyboard.press('Enter');
|
||||
// Enter would start editing D4 below (src/lib/editor/tableControls.ts:283), so leave the table to render both results.
|
||||
await page.keyboard.press('Control+Enter');
|
||||
assert.equal(await result(2, 3).innerText(), '#CYCLE!');
|
||||
assert.equal(await result(3, 3).innerText(), '#CYCLE!');
|
||||
await cell(2, 3).click();
|
||||
@@ -157,34 +114,17 @@ try {
|
||||
const saved = await save();
|
||||
assert.match(saved, /=SUM\(B2:B3\)/);
|
||||
assert.doesNotMatch(saved, /\\=/);
|
||||
// Footer controls share one normal-flow block aligned to the table at any width.
|
||||
async function checkFooter() {
|
||||
const geometry = await page.evaluate(() => {
|
||||
const rect = selector => document.querySelector(selector).getBoundingClientRect().toJSON();
|
||||
return { table: rect('.live-writer .md-table-scroll'), footer: rect('.table-footer'), tools: rect('.table-formula-tools'), help: rect('.table-edit-help'), helpHidden: document.querySelector('.table-edit-help').hidden, summary: rect('.table-formula-help summary'), status: rect('.table-formula-status') };
|
||||
});
|
||||
assert.ok(Math.abs(geometry.table.x - geometry.footer.x) < 2);
|
||||
assert.ok(Math.abs(geometry.footer.x - geometry.tools.x) < 2);
|
||||
if (!geometry.helpHidden) assert.ok(Math.abs(geometry.help.x - geometry.tools.x) < 2);
|
||||
assert.ok(geometry.footer.y >= geometry.table.bottom);
|
||||
assert.ok(geometry.footer.y - geometry.table.bottom <= 28, 'Only the add-row control sits between table and footer');
|
||||
if (!geometry.helpHidden) {
|
||||
assert.ok(geometry.tools.y >= geometry.help.bottom, 'Help must not overlap the controls');
|
||||
assert.ok(geometry.help.right <= geometry.footer.right + 1);
|
||||
}
|
||||
if (geometry.status.x > geometry.summary.right) assert.ok(Math.abs((geometry.status.y + geometry.status.height / 2) - (geometry.summary.y + geometry.summary.height / 2)) < 2);
|
||||
}
|
||||
await cell(3, 1).click();
|
||||
await checkFooter();
|
||||
await page.screenshot({ path: '.audit/table-formula-footer.png' });
|
||||
await shot('footer');
|
||||
await page.setViewportSize({ width: 850, height: 1000 });
|
||||
await checkFooter();
|
||||
await page.screenshot({ path: '.audit/table-formula-footer-narrow.png' });
|
||||
await shot('footer-narrow');
|
||||
await page.locator('.table-formula-help summary').click();
|
||||
assert.equal(await page.locator('.table-formula-help').getAttribute('open'), '');
|
||||
await checkFooter();
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
await page.screenshot({ path: '.audit/table-formulas.png' });
|
||||
await shot('formulas');
|
||||
await page.keyboard.press('Control+e');
|
||||
await page.keyboard.press('Control+e');
|
||||
assert.equal(await result(3, 1).innerText(), '12');
|
||||
@@ -193,8 +133,8 @@ try {
|
||||
await page.getByRole('group', { name: 'Document view', exact: true }).getByRole('button', { pressed: true }).press('ArrowRight');
|
||||
const preview = page.locator('.md-page table').first();
|
||||
await preview.waitFor();
|
||||
assert.equal(await preview.locator('tbody tr').last().locator('.md-table-formula').last().innerText(), '58');
|
||||
// Enter in the last row added an empty row below Total (src/lib/editor/tableControls.ts:285).
|
||||
const total = preview.locator('tbody tr').filter({ hasText: 'Total' });
|
||||
assert.equal(await total.locator('.md-table-formula').last().innerText(), '58', `${mode} view`);
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
console.log('PASS: live recalculation, raw formula editing, Enter/Tab, undo/redo, cycle recovery, Markdown saves, help, remount, Read, and Split');
|
||||
} finally { await browser.close(); }
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user