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,62 +1,33 @@
|
||||
import { createRequire } from "node:module";
|
||||
// Editor menu surfaces: Writer, spelling, IDE, and code menus share the file menu styles; code tint and the command palette match in both themes.
|
||||
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(15000);
|
||||
const errors = [];
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
await mkdir(".audit", { recursive: true });
|
||||
await page.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const root = "C:\\tab-menu-workspace";
|
||||
const files = new Map(["a.md", "b.md", "c.md", "d.md"].map(name => [name, `# ${name}\n\nOriginal text.\n\n\`\`\`js\nconst answer = 42;\n\`\`\`\n\n| Name | Value |\n| --- | --- |\n| Alpha | One |\n`]));
|
||||
files.set("sample.txt", "const answer = 42;\n");
|
||||
window.tabMenuTest = { prompts: [], answer: "Cancel", revealed: null, clipboard: null };
|
||||
Object.defineProperty(navigator, "clipboard", { value: { writeText: async text => { window.tabMenuTest.clipboard = text; } } });
|
||||
let sequence = 0;
|
||||
const callbacks = new Map(), listeners = new Map();
|
||||
window.spellingTest = { commands: [], emit: payload => callbacks.get(listeners.get("spelling-menu"))?.({ event: "spelling-menu", id: 1, payload }) };
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
||||
transformCallback: callback => { callbacks.set(++sequence, callback); return sequence; }, unregisterCallback: id => callbacks.delete(id),
|
||||
invoke: async (command, args = {}) => {
|
||||
if (command === "plugin:event|listen") { listeners.set(args.event, args.handler); return ++sequence; }
|
||||
if (command === "plugin:event|unlisten") return;
|
||||
if (command.startsWith("spelling_menu_")) { window.spellingTest.commands.push({ method: command, ...args }); return; }
|
||||
if (command === "spelling_suggestions") return { language: "en-US", words: ["Corrected"], misspelled: args.word === "Original" };
|
||||
if (command === "workspace_last_path") return root;
|
||||
if (command === "workspace_open") return { root, name: "tab-menu-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_list") return args.rel ? [] : [{ name: "notes", rel_path: "notes", kind: "folder" }, ...[...files.keys()].map(name => ({ name, rel_path: name, kind: "file" }))];
|
||||
if (command === "workspace_search") return [];
|
||||
if (command === "workspace_write") throw new Error("Keep unsaved edits for the close test");
|
||||
if (command === "workspace_rename") { files.set(args.to, files.get(args.from)); files.delete(args.from); return; }
|
||||
if (command === "workspace_abs_path") return `${root}\\${args.rel}`;
|
||||
if (command === "workspace_reveal") { window.tabMenuTest.revealed = args.rel; return; }
|
||||
if (command === "plugin:dialog|message") { window.tabMenuTest.prompts.push(args.message); return window.tabMenuTest.answer; }
|
||||
throw new Error(`Unhandled IPC: ${command}`);
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("editor/surfaces", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const note = name => `# ${name}\n\nOriginal text.\n\n\`\`\`js\nconst answer = 42;\n\`\`\`\n\n| Name | Value |\n| --- | --- |\n| Alpha | One |\n`;
|
||||
return {
|
||||
...test.workspace({
|
||||
root: "C:\\tab-menu-workspace",
|
||||
files: { ...Object.fromEntries(["a.md", "b.md", "c.md", "d.md"].map(name => [name, note(name)])), "sample.txt": "const answer = 42;\n" },
|
||||
folders: ["notes"],
|
||||
}),
|
||||
spelling_menu_install: () => null,
|
||||
spelling_suggestions: ({ word }) => ({ language: "en-US", words: ["Corrected"], misspelled: word === "Original" }),
|
||||
};
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
||||
});
|
||||
|
||||
|
||||
const menu = name => page.getByRole('menu', { name, exact: true });
|
||||
const item = name => page.getByRole('menuitem', { name, exact: true });
|
||||
const output = '.audit/editor-surfaces';
|
||||
await mkdir(output, { recursive: true });
|
||||
const report = [];
|
||||
const dismiss = async () => { await page.keyboard.press('Escape'); await page.locator('.rs-menu').waitFor({ state: 'detached' }); };
|
||||
const styles = panel => panel.evaluate(node => {
|
||||
const row = node.querySelector(':scope > button');
|
||||
const a = getComputedStyle(node), b = getComputedStyle(row);
|
||||
return [a.backgroundColor, a.borderRadius, a.padding, b.minHeight, b.padding, b.font];
|
||||
});
|
||||
try {
|
||||
await page.goto(process.env.SMOKE_URL || 'http://127.0.0.1:1420');
|
||||
});
|
||||
const menu = name => page.getByRole('menu', { name, exact: true });
|
||||
const item = name => page.getByRole('menuitem', { name, exact: true });
|
||||
const output = await outputDir("editor/surfaces");
|
||||
const report = [];
|
||||
const dismiss = async () => { await page.keyboard.press('Escape'); await page.locator('.rs-menu').waitFor({ state: 'detached' }); };
|
||||
const styles = panel => panel.evaluate(node => {
|
||||
const row = node.querySelector(':scope > button');
|
||||
const a = getComputedStyle(node), b = getComputedStyle(row);
|
||||
return [a.backgroundColor, a.borderRadius, a.padding, b.minHeight, b.padding, b.font];
|
||||
});
|
||||
await page.goto(smokeUrl);
|
||||
await page.locator('[data-tree-rel="a.md"]').click();
|
||||
await page.locator('.cm-content').waitFor();
|
||||
for (const theme of ['dark', 'light']) {
|
||||
@@ -176,6 +147,5 @@ try {
|
||||
await page.getByRole('button', { name: 'Writer', exact: true }).click();
|
||||
report.push({ theme, passed: ['word and blank menu parity', 'spelling correction and undo', 'Writer/IDE parity', 'undo menu action', 'code menu host styles', 'transparent code in Writer/Reader', 'palette selection/focus', 'narrow keyboard menu/palette'], nativeDesktop: 'not tested' });
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
console.log(JSON.stringify(report, null, 2));
|
||||
} catch (error) { await page.screenshot({path: `${output}/failure.png`}); console.log(await page.locator(".rs-menu").allTextContents()); throw error; } finally { await browser.close(); }
|
||||
}, { timeout: 15000 });
|
||||
|
||||
Reference in New Issue
Block a user