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,55 +1,38 @@
|
||||
// Run against pnpm dev with PLAYWRIGHT_MODULE and CHROME_PATH if needed.
|
||||
import { createRequire } from "node:module";
|
||||
// Sidebar layout persistence: the hidden outline, resized sidebars, and the navigation view survive layout changes, reloads, and reopened windows.
|
||||
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 context = await browser.newContext({ viewport: { width: 1280, height: 800 } });
|
||||
await context.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
||||
transformCallback: () => 1, unregisterCallback: () => {},
|
||||
invoke: async (command, args = {}) => {
|
||||
if (command === "plugins_snapshot") return { root: "D:\\LayoutTest\\plugins", plugins: [] };
|
||||
if (command === "workspace_last_path") return "D:\\LayoutTest";
|
||||
if (command === "workspace_open") return { root: "D:\\LayoutTest", name: "LayoutTest", watch_mode: "native" };
|
||||
if (command === "workspace_list") return args.rel ? [] : [{ name: "note.md", rel_path: "note.md", kind: "file" }];
|
||||
if (command === "workspace_read") {
|
||||
if (args.rel === "note.md") return "# Layout test\n\nA note.\n";
|
||||
throw new Error("Missing file");
|
||||
}
|
||||
return null;
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
||||
});
|
||||
const errors = [];
|
||||
context.on("page", page => page.on("pageerror", error => errors.push(error.message)));
|
||||
const url = process.env.SMOKE_URL || "http://127.0.0.1:1420";
|
||||
let page = await context.newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
async function ready() { await page.getByRole("button", { name: /^(Hide|Show) outline$/ }).waitFor(); }
|
||||
async function reopen() {
|
||||
await page.close();
|
||||
page = await context.newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
await page.goto(url);
|
||||
await ready();
|
||||
}
|
||||
async function resize(index, x) {
|
||||
const box = await page.locator(".gutter-v").nth(index).boundingBox();
|
||||
await page.mouse.move(box.x + box.width / 2, box.y + 60);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(x, box.y + 60);
|
||||
await page.mouse.up();
|
||||
}
|
||||
async function widths() {
|
||||
return page.locator(".shell").evaluate(element => [element.style.getPropertyValue("--left"), element.style.getPropertyValue("--right")]);
|
||||
}
|
||||
try {
|
||||
await page.goto(url);
|
||||
await ready();
|
||||
import { mockTauri, openPage, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("layout/outline", async ({ browser }) => {
|
||||
// Pages share one context, so a reopened window keeps the saved layout.
|
||||
const context = await browser.newContext({ viewport: { width: 1280, height: 800 } });
|
||||
// Unknown commands return null, as the original mock did.
|
||||
await mockTauri(context, {
|
||||
strict: false,
|
||||
commands: test => ({
|
||||
...test.workspace({ root: "D:\\LayoutTest", files: { "note.md": "# Layout test\n\nA note.\n" } }),
|
||||
plugins_snapshot: () => ({ root: "D:\\LayoutTest\\plugins", plugins: [] }),
|
||||
}),
|
||||
});
|
||||
const errors = [];
|
||||
let page;
|
||||
async function ready() { await page.getByRole("button", { name: /^(Hide|Show) outline$/ }).waitFor(); }
|
||||
async function reopen() {
|
||||
if (page) { errors.push(...page.errors); await page.close(); }
|
||||
page = await openPage(context, { timeout: 5000 });
|
||||
await page.goto(smokeUrl);
|
||||
await ready();
|
||||
}
|
||||
async function resize(index, x) {
|
||||
const box = await page.locator(".gutter-v").nth(index).boundingBox();
|
||||
await page.mouse.move(box.x + box.width / 2, box.y + 60);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(x, box.y + 60);
|
||||
await page.mouse.up();
|
||||
}
|
||||
async function widths() {
|
||||
return page.locator(".shell").evaluate(element => [element.style.getPropertyValue("--left"), element.style.getPropertyValue("--right")]);
|
||||
}
|
||||
await reopen();
|
||||
await page.getByText("LayoutTest", { exact: true }).waitFor();
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill("note.md");
|
||||
@@ -91,5 +74,6 @@ try {
|
||||
await page.getByRole("button", { name: "Show outline", exact: true }).click();
|
||||
assert.deepEqual(await widths(), resized);
|
||||
console.log("PASS: collapsed sidebars retain their sizes and navigation view");
|
||||
errors.push(...page.errors);
|
||||
assert.deepEqual(errors, []);
|
||||
} finally { await browser.close(); }
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user