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,182 +1,128 @@
|
||||
// Run against `pnpm dev`. PLAYWRIGHT_MODULE may point to a shared installation.
|
||||
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 page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
|
||||
page.setDefaultTimeout(10000);
|
||||
const errors = [];
|
||||
await mkdir(".audit", { recursive: true });
|
||||
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 === "spelling_menu_install") return;
|
||||
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 };
|
||||
});
|
||||
|
||||
try {
|
||||
await mkdir("output/editor-october12", { recursive: true });
|
||||
await page.goto(process.env.SMOKE_URL || "http://127.0.0.1:1420");
|
||||
await page.getByText("smoke-workspace", { exact: true }).waitFor();
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill("welcome.md");
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: "welcome.md" }).first().click();
|
||||
await page.getByRole("textbox", { name: "Writing editor", exact: true }).waitFor();
|
||||
async function editor() {
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
window.__CM__ = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
});
|
||||
}
|
||||
await editor();
|
||||
const source = "# First section\n\nParent text.[^long]\n\n## Child section\n\nChild content.\n\n### Nested section\n\nNested content.\n\n# Second section\n\nSecond content.[^long]\n\n## Last section\n\nFinal content.\n\n[^long]: A **bold** footnote.\n Continued on another line.\n";
|
||||
async function setSource(value) {
|
||||
await page.evaluate(value => window.__CM__.dispatch({ changes: { from: 0, to: window.__CM__.state.doc.length, insert: value }, selection: { anchor: 0 } }), value);
|
||||
}
|
||||
await setSource(source);
|
||||
const structural = "# Parent\n\n| A | B |\n| --- | --- |\n| 1 | 2 |\n\n```md\n# Not a heading\n```\n\n## Child\n\nText\n\n# Next\n\nNext text\n";
|
||||
await setSource(structural);
|
||||
assert.equal(await page.getByRole("button", { name: "Collapse Not a heading", exact: true }).count(), 0);
|
||||
await page.getByRole("button", { name: "Collapse Parent", exact: true }).click();
|
||||
assert.equal(await page.locator(".writer-table").count(), 0);
|
||||
assert.equal(await page.getByRole("button", { name: "Collapse Child", exact: true }).count(), 0);
|
||||
await page.getByRole("button", { name: "Expand Parent", exact: true }).click();
|
||||
await page.locator(".writer-table").waitFor();
|
||||
assert.equal(await page.evaluate(() => window.__CM__.state.sliceDoc()), structural);
|
||||
await setSource("Setext heading\n==============\n\nBody\n\n# Next\n\nNext body");
|
||||
await page.getByRole("button", { name: "Collapse Setext heading", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Expand Setext heading", exact: true }).click();
|
||||
await setSource(source);
|
||||
await page.getByRole("button", { name: "Collapse Child section", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Expand Child section", exact: true }).waitFor();
|
||||
assert.equal(await page.locator(".cm-content").textContent().then(text => text.includes("Child content.")), false);
|
||||
await page.getByRole("button", { name: "Collapse First section", exact: true }).click();
|
||||
assert.equal(await page.getByRole("button", { name: "Expand Child section", exact: true }).count(), 0);
|
||||
await page.getByRole("button", { name: "Expand First section", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Expand Child section", exact: true }).waitFor();
|
||||
await page.getByRole("button", { name: "Expand Child section", exact: true }).focus();
|
||||
await page.keyboard.press("Enter");
|
||||
await page.getByRole("button", { name: "Collapse Child section", exact: true }).waitFor();
|
||||
assert.equal(await page.evaluate(() => document.activeElement?.getAttribute('aria-label')), 'Collapse Child section');
|
||||
assert.equal(await page.evaluate(() => window.__CM__.state.sliceDoc()), source);
|
||||
|
||||
// Insert from the real shared menu and edit the selected definition.
|
||||
await page.evaluate(() => { window.__CM__.dispatch({ selection: { anchor: 20 } }); window.__CM__.focus(); });
|
||||
await page.keyboard.press("Shift+F10");
|
||||
await page.getByRole("menuitem", { name: "Insert", exact: true }).hover();
|
||||
await page.getByRole("menuitem", { name: "Footnote", exact: true }).click();
|
||||
await page.keyboard.type("New footnote");
|
||||
assert.match(await page.evaluate(() => window.__CM__.state.sliceDoc()), /\[\^1\]: New footnote/);
|
||||
await page.keyboard.press("Control+z");
|
||||
await setSource(source);
|
||||
|
||||
for (const theme of ["light", "dark"]) {
|
||||
await page.evaluate(async theme => { const { applyAppearance } = await import('/src/lib/theme/appearance.ts'); applyAppearance({ theme: 'default', mode: theme }); }, theme);
|
||||
await page.setViewportSize({ width: 760, height: 900 });
|
||||
await page.getByRole("button", { name: "Collapse Child section", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Expand Child section", exact: true }).focus();
|
||||
assert.ok(await page.getByRole("button", { name: "Expand Child section", exact: true }).evaluate(button => {
|
||||
const bounds = button.getBoundingClientRect();
|
||||
const pane = button.closest('.cm-scroller').getBoundingClientRect();
|
||||
return bounds.left >= pane.left && bounds.right <= pane.right;
|
||||
}));
|
||||
await page.screenshot({ path: `output/editor-october12/writer-${theme}-narrow.png` });
|
||||
await page.keyboard.press("Space");
|
||||
const borders = await page.locator(".writer-heading").evaluateAll(headings => headings.map(heading => getComputedStyle(heading).borderBottomWidth));
|
||||
assert.ok(borders.every(border => border === "0px"));
|
||||
assert.ok(await page.locator(".writer-heading").first().evaluate(heading => parseFloat(getComputedStyle(heading).paddingTop) > 8));
|
||||
await page.getByRole("group", { name: "Document view" }).hover();
|
||||
await page.getByRole("button", { name: "Read", exact: true }).click();
|
||||
await page.locator(".md-footnotes").waitFor();
|
||||
assert.equal(await page.locator(".md-footnote-ref").count(), 2);
|
||||
assert.equal(await page.locator(".md-footnotes li").count(), 1);
|
||||
assert.equal(await page.locator(".md-footnote-back").count(), 2);
|
||||
await page.getByRole("button", { name: "Collapse Child section", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Expand Child section", exact: true }).focus();
|
||||
assert.ok(await page.getByRole("button", { name: "Expand Child section", exact: true }).evaluate(button => {
|
||||
const bounds = button.getBoundingClientRect();
|
||||
const pane = button.closest('.reading').parentElement.getBoundingClientRect();
|
||||
return bounds.left >= pane.left && bounds.right <= pane.right;
|
||||
}));
|
||||
assert.equal(await page.getByText("Child content.", { exact: true }).isVisible(), false);
|
||||
await page.screenshot({ path: `output/editor-october12/reader-${theme}-narrow.png` });
|
||||
await page.keyboard.press("Space");
|
||||
assert.equal(await page.getByText("Child content.", { exact: true }).isVisible(), true);
|
||||
await page.getByRole("button", { name: "Collapse Last section", exact: true }).click();
|
||||
await page.locator(".md-footnote-ref a").first().click();
|
||||
assert.equal(await page.locator(".md-footnotes").isVisible(), true);
|
||||
await page.locator(".md-footnote-back").first().click();
|
||||
assert.equal(await page.evaluate(() => document.activeElement?.id), "rs-fnref-1-1");
|
||||
await page.getByRole("group", { name: "Document view" }).hover();
|
||||
await page.getByRole("button", { name: "Edit", exact: true }).click();
|
||||
await page.getByRole("textbox", { name: "Writing editor", exact: true }).waitFor();
|
||||
await editor();
|
||||
}
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(value => window.__TEST__.files.get("notes/welcome.md") === value, source);
|
||||
assert.deepEqual(errors, []);
|
||||
console.log("PASS: footnote menu, Writer edits, Reader numbering and backlinks, nested folding, keyboard toggles, source preservation, light/dark narrow screenshots.");
|
||||
} catch (error) {
|
||||
console.error("Browser errors:", errors);
|
||||
await page.screenshot({ path: "output/editor-october12/failure.png" });
|
||||
throw error;
|
||||
} finally { await browser.close(); }
|
||||
␍
|
||||
// Footnotes and heading folds: the footnote menu, Reader numbering and backlinks, nested folding, keyboard toggles, and source preservation.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("editor/footnotes", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const workspace = test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
files: {
|
||||
"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",
|
||||
},
|
||||
writeEvents: true,
|
||||
});
|
||||
test.files = workspace.files;
|
||||
return {
|
||||
...workspace,
|
||||
// Saves send the last saved text. Reject a save when the file changed, as the backend does.
|
||||
workspace_write: args => {
|
||||
if (args.expected !== undefined && workspace.files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
|
||||
return workspace.workspace_write(args);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
const output = await outputDir("editor/footnotes");
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText("smoke-workspace", { exact: true }).waitFor();
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill("welcome.md");
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: "welcome.md" }).first().click();
|
||||
await page.getByRole("textbox", { name: "Writing editor", exact: true }).waitFor();
|
||||
async function editor() {
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
window.__CM__ = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
});
|
||||
}
|
||||
await editor();
|
||||
const source = "# First section\n\nParent text.[^long]\n\n## Child section\n\nChild content.\n\n### Nested section\n\nNested content.\n\n# Second section\n\nSecond content.[^long]\n\n## Last section\n\nFinal content.\n\n[^long]: A **bold** footnote.\n Continued on another line.\n";
|
||||
async function setSource(value) {
|
||||
await page.evaluate(value => window.__CM__.dispatch({ changes: { from: 0, to: window.__CM__.state.doc.length, insert: value }, selection: { anchor: 0 } }), value);
|
||||
}
|
||||
await setSource(source);
|
||||
const structural = "# Parent\n\n| A | B |\n| --- | --- |\n| 1 | 2 |\n\n```md\n# Not a heading\n```\n\n## Child\n\nText\n\n# Next\n\nNext text\n";
|
||||
await setSource(structural);
|
||||
assert.equal(await page.getByRole("button", { name: "Collapse Not a heading", exact: true }).count(), 0);
|
||||
await page.getByRole("button", { name: "Collapse Parent", exact: true }).click();
|
||||
assert.equal(await page.locator(".writer-table").count(), 0);
|
||||
assert.equal(await page.getByRole("button", { name: "Collapse Child", exact: true }).count(), 0);
|
||||
await page.getByRole("button", { name: "Expand Parent", exact: true }).click();
|
||||
await page.locator(".writer-table").waitFor();
|
||||
assert.equal(await page.evaluate(() => window.__CM__.state.sliceDoc()), structural);
|
||||
await setSource("Setext heading\n==============\n\nBody\n\n# Next\n\nNext body");
|
||||
await page.getByRole("button", { name: "Collapse Setext heading", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Expand Setext heading", exact: true }).click();
|
||||
await setSource(source);
|
||||
await page.getByRole("button", { name: "Collapse Child section", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Expand Child section", exact: true }).waitFor();
|
||||
assert.equal(await page.locator(".cm-content").textContent().then(text => text.includes("Child content.")), false);
|
||||
await page.getByRole("button", { name: "Collapse First section", exact: true }).click();
|
||||
assert.equal(await page.getByRole("button", { name: "Expand Child section", exact: true }).count(), 0);
|
||||
await page.getByRole("button", { name: "Expand First section", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Expand Child section", exact: true }).waitFor();
|
||||
await page.getByRole("button", { name: "Expand Child section", exact: true }).focus();
|
||||
await page.keyboard.press("Enter");
|
||||
await page.getByRole("button", { name: "Collapse Child section", exact: true }).waitFor();
|
||||
assert.equal(await page.evaluate(() => document.activeElement?.getAttribute('aria-label')), 'Collapse Child section');
|
||||
assert.equal(await page.evaluate(() => window.__CM__.state.sliceDoc()), source);
|
||||
|
||||
// Insert from the real shared menu and edit the selected definition.
|
||||
await page.evaluate(() => { window.__CM__.dispatch({ selection: { anchor: 20 } }); window.__CM__.focus(); });
|
||||
await page.keyboard.press("Shift+F10");
|
||||
await page.getByRole("menuitem", { name: "Insert", exact: true }).hover();
|
||||
await page.getByRole("menuitem", { name: "Footnote", exact: true }).click();
|
||||
await page.keyboard.type("New footnote");
|
||||
assert.match(await page.evaluate(() => window.__CM__.state.sliceDoc()), /\[\^1\]: New footnote/);
|
||||
await page.keyboard.press("Control+z");
|
||||
await setSource(source);
|
||||
|
||||
for (const theme of ["light", "dark"]) {
|
||||
await page.evaluate(async theme => { const { applyAppearance } = await import('/src/lib/theme/appearance.ts'); applyAppearance({ theme: 'default', mode: theme }); }, theme);
|
||||
await page.setViewportSize({ width: 760, height: 900 });
|
||||
await page.getByRole("button", { name: "Collapse Child section", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Expand Child section", exact: true }).focus();
|
||||
assert.ok(await page.getByRole("button", { name: "Expand Child section", exact: true }).evaluate(button => {
|
||||
const bounds = button.getBoundingClientRect();
|
||||
const pane = button.closest('.cm-scroller').getBoundingClientRect();
|
||||
return bounds.left >= pane.left && bounds.right <= pane.right;
|
||||
}));
|
||||
await page.screenshot({ path: `${output}/writer-${theme}-narrow.png` });
|
||||
await page.keyboard.press("Space");
|
||||
const borders = await page.locator(".writer-heading").evaluateAll(headings => headings.map(heading => getComputedStyle(heading).borderBottomWidth));
|
||||
assert.ok(borders.every(border => border === "0px"));
|
||||
assert.ok(await page.locator(".writer-heading").first().evaluate(heading => parseFloat(getComputedStyle(heading).paddingTop) > 8));
|
||||
await page.getByRole("group", { name: "Document view" }).hover();
|
||||
await page.getByRole("button", { name: "Read", exact: true }).click();
|
||||
await page.locator(".md-footnotes").waitFor();
|
||||
assert.equal(await page.locator(".md-footnote-ref").count(), 2);
|
||||
assert.equal(await page.locator(".md-footnotes li").count(), 1);
|
||||
assert.equal(await page.locator(".md-footnote-back").count(), 2);
|
||||
await page.getByRole("button", { name: "Collapse Child section", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Expand Child section", exact: true }).focus();
|
||||
assert.ok(await page.getByRole("button", { name: "Expand Child section", exact: true }).evaluate(button => {
|
||||
const bounds = button.getBoundingClientRect();
|
||||
const pane = button.closest('.reading').parentElement.getBoundingClientRect();
|
||||
return bounds.left >= pane.left && bounds.right <= pane.right;
|
||||
}));
|
||||
assert.equal(await page.getByText("Child content.", { exact: true }).isVisible(), false);
|
||||
await page.screenshot({ path: `${output}/reader-${theme}-narrow.png` });
|
||||
await page.keyboard.press("Space");
|
||||
assert.equal(await page.getByText("Child content.", { exact: true }).isVisible(), true);
|
||||
await page.getByRole("button", { name: "Collapse Last section", exact: true }).click();
|
||||
await page.locator(".md-footnote-ref a").first().click();
|
||||
assert.equal(await page.locator(".md-footnotes").isVisible(), true);
|
||||
await page.locator(".md-footnote-back").first().click();
|
||||
assert.equal(await page.evaluate(() => document.activeElement?.id), "rs-fnref-1-1");
|
||||
await page.getByRole("group", { name: "Document view" }).hover();
|
||||
await page.getByRole("button", { name: "Edit", exact: true }).click();
|
||||
await page.getByRole("textbox", { name: "Writing editor", exact: true }).waitFor();
|
||||
await editor();
|
||||
}
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(value => window.__TEST__.files.get("notes/welcome.md") === value, source);
|
||||
console.log("PASS: footnote menu, Writer edits, Reader numbering and backlinks, nested folding, keyboard toggles, source preservation, light/dark narrow screenshots.");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user