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,79 +1,72 @@
|
||||
import { createRequire } from "node:module";
|
||||
// Tab transfer between windows: same-workspace moves with unsaved text and pins, insertion order, other-workspace rejection, duplicates, and source edits during a transfer.
|
||||
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 context = await browser.newContext({ viewport: { width: 1440, height: 900 } });
|
||||
await context.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false }));
|
||||
const root = location.search.includes("other") ? "C:\\other" : "C:\\transfer";
|
||||
let sequence = 0;
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
||||
transformCallback: () => ++sequence, unregisterCallback: () => {},
|
||||
invoke: async (command, args = {}) => {
|
||||
if (command === "plugin:event|listen") return ++sequence;
|
||||
if (command === "plugin:event|unlisten" || command.startsWith("plugin:window|")) return;
|
||||
if (command === "workspace_last_path") return root;
|
||||
if (command === "workspace_open") return { root, name: "transfer", watch_mode: "native" };
|
||||
if (command === "workspace_read") return "# " + args.rel + "\n\nOriginal text.\n";
|
||||
if (command === "workspace_list") return args.rel ? [] : ["a.md", "b.md"].map(name => ({ name, rel_path: name, kind: "file" }));
|
||||
if (command === "workspace_search") return [];
|
||||
if (command === "plugins_snapshot") return { root, plugins: [] };
|
||||
throw new Error(`Unhandled IPC: ${command}`);
|
||||
import path from "node:path";
|
||||
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("tabs/transfer", async ({ browser }) => {
|
||||
const output = await outputDir("tabs/transfer");
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 900 } });
|
||||
await mockTauri(context, {
|
||||
commands: test => {
|
||||
localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false }));
|
||||
const root = location.search.includes("other") ? "C:\\other" : "C:\\transfer";
|
||||
const workspace = test.workspace({ root, name: "transfer", files: Object.fromEntries(["a.md", "b.md"].map(name => [name, `# ${name}\n\nOriginal text.\n`])) });
|
||||
return {
|
||||
...workspace,
|
||||
plugins_snapshot: () => ({ root, plugins: [] }),
|
||||
"plugin:window|is_maximized": () => false,
|
||||
};
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
||||
});
|
||||
const url = process.env.SMOKE_URL || "http://127.0.0.1:1420";
|
||||
const source = await context.newPage(), target = await context.newPage(), other = await context.newPage();
|
||||
for (const page of [source, target, other]) page.setDefaultTimeout(10000);
|
||||
const errors = [];
|
||||
for (const page of [source, target, other]) page.on("pageerror", error => errors.push(error.message));
|
||||
const tab = (page, name) => page.locator('[role="tab"]').filter({ hasText: name });
|
||||
async function open(page, name) {
|
||||
await page.bringToFront();
|
||||
await page.getByRole("tablist", { name: "Working tabs" }).waitFor();
|
||||
await page.getByRole("tab").first().waitFor();
|
||||
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 tab(page, name).waitFor();
|
||||
}
|
||||
async function start(page, name) {
|
||||
return tab(page, name).evaluate(node => {
|
||||
const transfer = new DataTransfer();
|
||||
node.dispatchEvent(new DragEvent("dragstart", { bubbles: true, dataTransfer: transfer }));
|
||||
return transfer.getData("application/x-runestone-tab");
|
||||
});
|
||||
}
|
||||
async function drop(page, data) {
|
||||
await page.getByRole("tablist", { name: "Working tabs" }).evaluate((node, data) => {
|
||||
const transfer = new DataTransfer();
|
||||
transfer.setData("application/x-runestone-tab", data);
|
||||
node.dispatchEvent(new DragEvent("dragover", { bubbles: true, cancelable: true, clientX: node.getBoundingClientRect().left, dataTransfer: transfer }));
|
||||
node.dispatchEvent(new DragEvent("drop", { bubbles: true, cancelable: true, clientX: node.getBoundingClientRect().left, dataTransfer: transfer }));
|
||||
}, data);
|
||||
}
|
||||
async function captureTransfer(page, data) {
|
||||
await mkdir("output/tab-transfer", { recursive: true });
|
||||
for (const theme of ["light", "dark"]) {
|
||||
const pages = [];
|
||||
async function newPage() {
|
||||
const page = await openPage(context);
|
||||
pages.push(page);
|
||||
return page;
|
||||
}
|
||||
const source = await newPage(), target = await newPage(), other = await newPage();
|
||||
const tab = (page, name) => page.locator('[role="tab"]').filter({ hasText: name });
|
||||
async function open(page, name) {
|
||||
await page.bringToFront();
|
||||
await page.getByRole("tablist", { name: "Working tabs" }).waitFor();
|
||||
await page.getByRole("tab").first().waitFor();
|
||||
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 tab(page, name).waitFor();
|
||||
}
|
||||
async function start(page, name) {
|
||||
return tab(page, name).evaluate(node => {
|
||||
const transfer = new DataTransfer();
|
||||
node.dispatchEvent(new DragEvent("dragstart", { bubbles: true, dataTransfer: transfer }));
|
||||
return transfer.getData("application/x-runestone-tab");
|
||||
});
|
||||
}
|
||||
function dragOver(page, data, drop) {
|
||||
return page.getByRole("tablist", { name: "Working tabs" }).evaluate((node, { data, drop }) => {
|
||||
const transfer = new DataTransfer();
|
||||
transfer.setData("application/x-runestone-tab", data);
|
||||
const options = { bubbles: true, cancelable: true, clientX: node.getBoundingClientRect().left, dataTransfer: transfer };
|
||||
node.dispatchEvent(new DragEvent("dragover", options));
|
||||
if (drop) node.dispatchEvent(new DragEvent("drop", options));
|
||||
}, { data, drop });
|
||||
}
|
||||
const drop = (page, data) => dragOver(page, data, true);
|
||||
async function setTheme(page, mode) {
|
||||
await page.evaluate(async mode => {
|
||||
const { applyAppearance } = await import('/src/lib/theme/appearance.ts');
|
||||
await applyAppearance({ theme: 'default', mode });
|
||||
}, theme);
|
||||
await page.getByRole("tablist", { name: "Working tabs" }).evaluate((node, data) => {
|
||||
const transfer = new DataTransfer();
|
||||
transfer.setData("application/x-runestone-tab", data);
|
||||
node.dispatchEvent(new DragEvent("dragover", { bubbles: true, cancelable: true, clientX: node.getBoundingClientRect().left, dataTransfer: transfer }));
|
||||
}, data);
|
||||
await page.screenshot({ path: `output/tab-transfer/${theme}-receiving.png` });
|
||||
}, mode);
|
||||
}
|
||||
}
|
||||
try {
|
||||
await Promise.all([source.goto(url), target.goto(url), other.goto(url + "/?other")]);
|
||||
async function captureTransfer(page, data) {
|
||||
for (const theme of ["light", "dark"]) {
|
||||
await setTheme(page, theme);
|
||||
await dragOver(page, data, false);
|
||||
await page.screenshot({ path: path.join(output, `${theme}-receiving.png`) });
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all([source.goto(smokeUrl), target.goto(smokeUrl), other.goto(smokeUrl + "/?other")]);
|
||||
await open(source, "a.md");
|
||||
await open(target, "b.md");
|
||||
await tab(source, "a.md").click({ button: "right" });
|
||||
@@ -86,14 +79,11 @@ try {
|
||||
assert.equal(await tab(source, "a.md").count(), 1);
|
||||
await captureTransfer(target, data);
|
||||
await drop(target, data);
|
||||
console.log("Dropped into matching workspace");
|
||||
await tab(target, "a.md").waitFor();
|
||||
await tab(source, "a.md").waitFor({ state: "detached" });
|
||||
console.log("Source acknowledged transfer");
|
||||
assert.match(await target.locator(".cm-content").innerText(), /Unsaved transfer text/);
|
||||
const changedTarget = await context.newPage();
|
||||
changedTarget.on("pageerror", error => errors.push(error.message));
|
||||
await changedTarget.goto(url);
|
||||
const changedTarget = await newPage();
|
||||
await changedTarget.goto(smokeUrl);
|
||||
await changedTarget.getByRole("tab").first().waitFor();
|
||||
await open(source, "a.md");
|
||||
data = await start(source, "a.md");
|
||||
@@ -110,20 +100,11 @@ try {
|
||||
await target.getByText("This tab is already open in this window. The source tab remains open.").waitFor();
|
||||
assert.equal(await tab(source, "a.md").count(), 1);
|
||||
assert.match(await target.locator(".cm-content").innerText(), /Unsaved transfer text/);
|
||||
await mkdir("output/tab-transfer", { recursive: true });
|
||||
for (const theme of ["light", "dark"]) {
|
||||
await target.evaluate(async mode => {
|
||||
const { applyAppearance } = await import('/src/lib/theme/appearance.ts');
|
||||
await applyAppearance({ theme: 'default', mode });
|
||||
}, theme);
|
||||
await target.screenshot({ path: `output/tab-transfer/${theme}.png` });
|
||||
await setTheme(target, theme);
|
||||
await target.screenshot({ path: path.join(output, `${theme}.png`) });
|
||||
}
|
||||
await target.setViewportSize({ width: 700, height: 700 });
|
||||
await target.screenshot({ path: "output/tab-transfer/narrow.png" });
|
||||
assert.deepEqual(errors, []);
|
||||
console.log("PASS: same-workspace transfer, unsaved text, pinned state, insertion order, other-workspace rejection, duplicate protection, and source edits during transfer");
|
||||
} catch (reason) {
|
||||
console.log(await other.locator("body").innerText());
|
||||
console.log(await target.locator("body").innerText());
|
||||
throw reason;
|
||||
} finally { await browser.close(); }
|
||||
await target.screenshot({ path: path.join(output, "narrow.png") });
|
||||
assert.deepEqual(pages.flatMap(page => page.errors), []);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user