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,117 +1,65 @@
|
||||
// Run against `pnpm dev`. PLAYWRIGHT_MODULE may point to a shared installation.
|
||||
import { createRequire } from "node:module";
|
||||
// Images dragged from the file tree: hidden source, selection, image menu actions, cancel, and source mode.
|
||||
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 svg = '<svg xmlns="http://www.w3.org/2000/svg" width="640" height="360"><rect width="640" height="360" fill="#486077"/><circle cx="320" cy="180" r="110" fill="#93cab5"/></svg>';
|
||||
files.set("images/picture (#1).svg", btoa(svg));
|
||||
files.set("images/replacement.svg", btoa(svg));
|
||||
files.set("notes/welcome.md", "Above.\n\nBelow.\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_write_bytes") {
|
||||
if (window.__TEST__.delay) await new Promise(resolve => { window.__TEST__.resume = resolve; });
|
||||
if (window.__TEST__.failWrite) throw new Error("Image write failed");
|
||||
files.set(args.rel, args.base64); return;
|
||||
}
|
||||
if (command === "workspace_read_data_url") {
|
||||
if (!files.has(args.rel)) throw new Error("missing image");
|
||||
return "data:image/svg+xml;base64," + files.get(args.rel);
|
||||
}
|
||||
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_reveal") 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, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("editor/imageNavigation", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
// Image files hold base64 SVG.
|
||||
const svg = btoa('<svg xmlns="http://www.w3.org/2000/svg" width="640" height="360"><rect width="640" height="360" fill="#486077"/><circle cx="320" cy="180" r="110" fill="#93cab5"/></svg>');
|
||||
const workspace = test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
files: {
|
||||
"notes/welcome.md": "Above.\n\nBelow.\n",
|
||||
"notes/second.md": "# Second note\n",
|
||||
"src/hello.py": "print('hello')\n",
|
||||
"images/picture (#1).svg": svg,
|
||||
"images/replacement.svg": svg,
|
||||
},
|
||||
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);
|
||||
},
|
||||
workspace_read_data_url: ({ rel }) => {
|
||||
if (!workspace.files.has(rel)) throw new Error("missing image");
|
||||
return "data:image/svg+xml;base64," + workspace.files.get(rel);
|
||||
},
|
||||
workspace_reveal: () => null,
|
||||
};
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: (_event, id) => callbacks.delete(id) };
|
||||
window.__TEST__ = { files, calls, emit, root };
|
||||
});
|
||||
|
||||
|
||||
|
||||
async function writer() {
|
||||
await page.locator(".cm-content").waitFor();
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
window.__CM__ = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
});
|
||||
}
|
||||
async function source() { return page.evaluate(() => window.__CM__.state.doc.toString()); }
|
||||
async function dragFromTree(selector = ".cm-content", cancel = false) {
|
||||
const row = page.locator('[data-tree-rel="images/picture (#1).svg"]');
|
||||
const from = await row.boundingBox(), to = await page.locator(selector).boundingBox();
|
||||
await page.mouse.move(from.x + 60, from.y + from.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(to.x + 40, to.y + 10, { steps: 12 });
|
||||
await page.getByText("Insert image", { exact: true }).waitFor();
|
||||
assert.equal(await page.locator(".image-drop-target").count(), 1);
|
||||
if (cancel) await page.keyboard.press("Escape");
|
||||
await page.mouse.up();
|
||||
}
|
||||
async function imageMenu() {
|
||||
await page.locator(".md-image-frame").first().click({ button: "right" });
|
||||
await page.getByRole("menu", { name: "Image actions" }).waitFor();
|
||||
}
|
||||
try {
|
||||
const output = await outputDir("editor/imageNavigation");
|
||||
async function writer() {
|
||||
await page.locator(".cm-content").waitFor();
|
||||
await page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
window.__CM__ = EditorView.findFromDOM(document.querySelector(".cm-content"));
|
||||
});
|
||||
}
|
||||
async function source() { return page.evaluate(() => window.__CM__.state.doc.toString()); }
|
||||
async function dragFromTree(selector = ".cm-content", cancel = false) {
|
||||
const row = page.locator('[data-tree-rel="images/picture (#1).svg"]');
|
||||
const from = await row.boundingBox(), to = await page.locator(selector).boundingBox();
|
||||
await page.mouse.move(from.x + 60, from.y + from.height / 2);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(to.x + 40, to.y + 10, { steps: 12 });
|
||||
await page.getByText("Insert image", { exact: true }).waitFor();
|
||||
assert.equal(await page.locator(".image-drop-target").count(), 1);
|
||||
if (cancel) await page.keyboard.press("Escape");
|
||||
await page.mouse.up();
|
||||
}
|
||||
async function imageMenu() {
|
||||
await page.locator(".md-image-frame").first().click({ button: "right" });
|
||||
await page.getByRole("menu", { name: "Image actions" }).waitFor();
|
||||
}
|
||||
await page.context().grantPermissions(["clipboard-read", "clipboard-write"]);
|
||||
await page.goto(process.env.SMOKE_URL || "http://127.0.0.1:1420");
|
||||
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");
|
||||
@@ -132,7 +80,7 @@ try {
|
||||
await page.keyboard.press("Shift+F10");
|
||||
await page.getByRole("menu", { name: "Image actions" }).waitFor();
|
||||
assert.equal(await page.locator(".md-image-frame.is-selected").count(), 1);
|
||||
await page.screenshot({ path: ".audit/image-context-menu.png" });
|
||||
await page.screenshot({ path: `${output}/image-context-menu.png` });
|
||||
await page.getByRole("menuitem", { name: "Copy Markdown", exact: true }).click();
|
||||
assert.equal(await page.evaluate(() => navigator.clipboard.readText()), "");
|
||||
await imageMenu();
|
||||
@@ -195,15 +143,13 @@ try {
|
||||
await page.keyboard.press("Escape");
|
||||
assert.equal(await page.locator(".cm-line").filter({ hasText: "![Reference]" }).count(), 0);
|
||||
// The same navigator drag works in the source editor.
|
||||
await page.getByRole("button", { name: "Switch to IDE layout (Ctrl E)", exact: true }).click();
|
||||
// The layout switcher names its buttons by mode (src/lib/layout/EditorPane.svelte:200-208, src/lib/ui/ModeSwitcher.svelte:96).
|
||||
await page.getByRole("group", { name: "Editor layout", exact: true }).hover();
|
||||
await page.getByRole("button", { name: "IDE", exact: true }).click();
|
||||
await page.locator(".monaco-editor textarea").waitFor();
|
||||
await dragFromTree(".monaco-editor .view-lines");
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(() => window.__TEST__.files.get("notes/welcome.md").includes("picture%20"));
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "workspace_write_bytes").length), 0);
|
||||
assert.deepEqual(errors, []);
|
||||
console.log("Navigator image drag, hidden source, selection, copy, swap, remove, open, reveal, cancel and source mode passed.");
|
||||
} catch (error) {
|
||||
await page.screenshot({ path: ".audit/image-navigation-failure.png" });
|
||||
console.error(errors); throw error;
|
||||
} finally { await browser.close(); }
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user