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,104 +1,93 @@
|
||||
// Run against pnpm dev with PLAYWRIGHT_MODULE and CHROME_PATH if needed.
|
||||
import { createRequire } from "node:module";
|
||||
// Compact layout: pane-aligned ribbon, square tables, focus-only tree outline, joined tabs, line hover marker, Git line history, narrow width.
|
||||
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 with a short paragraph.\n\nA second paragraph.\n\n| Name | Value |\n| --- | --- |\n| Alpha | 12 |\n| Beta | 24 |\n";
|
||||
throw new Error("Missing file");
|
||||
}
|
||||
return null;
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
||||
});
|
||||
import path from "node:path";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
const page = await context.newPage();
|
||||
page.setDefaultTimeout(30000);
|
||||
const errors = [];
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
const url = process.env.SMOKE_URL || "http://127.0.0.1:5174";
|
||||
const row = page.locator('[data-tree-rel="note.md"]');
|
||||
try {
|
||||
await page.goto(url);
|
||||
await runSmoke("appearance/density", async ({ page }) => {
|
||||
const output = await outputDir("appearance/density");
|
||||
await page.setViewportSize({ width: 1280, height: 800 });
|
||||
await mockTauri(page, {
|
||||
commands: test => ({
|
||||
...test.workspace({
|
||||
root: "D:\\LayoutTest",
|
||||
files: { "note.md": "# Layout test\n\nA note with a short paragraph.\n\nA second paragraph.\n\n| Name | Value |\n| --- | --- |\n| Alpha | 12 |\n| Beta | 24 |\n" },
|
||||
}),
|
||||
plugins_snapshot: () => ({ root: "D:\\LayoutTest\\plugins", plugins: [] }),
|
||||
}),
|
||||
});
|
||||
const row = page.locator('[data-tree-rel="note.md"]');
|
||||
const documentView = () => page.getByRole("group", { name: "Document view" }).locator("button.current");
|
||||
const editorLayout = () => page.getByRole("group", { name: "Editor layout" }).locator("button.current");
|
||||
const setTheme = theme => page.evaluate(theme => { document.documentElement.dataset.theme = theme; }, theme);
|
||||
|
||||
await page.goto(smokeUrl);
|
||||
await row.waitFor();
|
||||
await row.click();
|
||||
await page.locator('.writer-table table').waitFor();
|
||||
const alignment = await page.evaluate(() => ({header:document.querySelector('.header-left').getBoundingClientRect().right, content:document.querySelector('.center').getBoundingClientRect().left}));
|
||||
await page.locator(".writer-table table").waitFor();
|
||||
const alignment = await page.evaluate(() => ({ header: document.querySelector(".header-left").getBoundingClientRect().right, content: document.querySelector(".center").getBoundingClientRect().left }));
|
||||
assert.ok(Math.abs(alignment.header - alignment.content) <= 1, JSON.stringify(alignment));
|
||||
const table = await page.locator('.writer-table table').evaluate(el => ({width:el.getBoundingClientRect().width, heights:[...el.rows].map(row=>row.getBoundingClientRect().height), radius:getComputedStyle(el.parentElement).borderRadius}));
|
||||
const table = await page.locator(".writer-table table").evaluate(el => ({ width: el.getBoundingClientRect().width, heights: [...el.rows].map(row => row.getBoundingClientRect().height), radius: getComputedStyle(el.parentElement).borderRadius }));
|
||||
assert.ok(table.width < 400, JSON.stringify(table));
|
||||
assert.ok(table.heights.every(height => height <= 36), JSON.stringify(table));
|
||||
assert.equal(table.radius, '0px');
|
||||
assert.equal(table.radius, "0px");
|
||||
await row.focus();
|
||||
assert.equal(await row.locator('.selection-outline').evaluate(el=>getComputedStyle(el).visibility), 'visible');
|
||||
await page.locator('.cm-content').click({position:{x:80,y:100}});
|
||||
assert.equal(await row.locator('.selection-outline').evaluate(el=>getComputedStyle(el).visibility), 'hidden');
|
||||
assert.equal(await row.getAttribute('aria-selected'), 'true');
|
||||
const line = page.locator('.cm-line').filter({hasText:'A second paragraph.'});
|
||||
assert.equal(await row.locator(".selection-outline").evaluate(el => getComputedStyle(el).visibility), "visible");
|
||||
await page.locator(".cm-content").click({ position: { x: 80, y: 100 } });
|
||||
assert.equal(await row.locator(".selection-outline").evaluate(el => getComputedStyle(el).visibility), "hidden");
|
||||
assert.equal(await row.getAttribute("aria-selected"), "true");
|
||||
const line = page.locator(".cm-line").filter({ hasText: "A second paragraph." });
|
||||
await line.hover();
|
||||
assert.equal(await line.evaluate(el=>getComputedStyle(el,'::before').width), '3px');
|
||||
assert.equal(await page.locator('.line-history').count(),0);
|
||||
await page.evaluate(async()=>{
|
||||
const {pluginHost}=await import('/src/lib/plugins/registry.ts');
|
||||
window.blameCalls=[];
|
||||
window.removeGit=pluginHost.register('ui-test','git',{blame:async(path,line)=>{
|
||||
window.blameCalls.push({path,line});
|
||||
return {commit:'123456789abcdef',author:'UI test',date:'2026-10-07T12:34:00Z',summary:`Changed line ${line}`};
|
||||
}});
|
||||
assert.equal(await line.evaluate(el => getComputedStyle(el, "::before").width), "3px");
|
||||
assert.equal(await page.locator(".line-history").count(), 0);
|
||||
|
||||
await page.evaluate(async () => {
|
||||
const { pluginHost } = await import("/src/lib/plugins/registry.ts");
|
||||
window.blameCalls = [];
|
||||
window.removeGit = pluginHost.register("ui-test", "git", { blame: async (path, line) => {
|
||||
window.blameCalls.push({ path, line });
|
||||
return { commit: "123456789abcdef", author: "UI test", date: "2026-10-07T12:34:00Z", summary: `Changed line ${line}` };
|
||||
} });
|
||||
});
|
||||
await line.click();
|
||||
await page.locator('.line-history').waitFor();
|
||||
assert.match(await page.locator('.line-history').getAttribute('title'), /Line 5 · UI test/);
|
||||
await page.keyboard.type('x');
|
||||
await page.locator('.line-history').waitFor({state:'hidden'});
|
||||
await page.keyboard.press('Control+z');
|
||||
await page.locator('.line-history').waitFor();
|
||||
for(const theme of ['dark','light']) {
|
||||
await page.evaluate(theme=>document.documentElement.dataset.theme=theme,theme);
|
||||
const tab = await page.locator('.tab.active').evaluate(el=>({background:getComputedStyle(el).backgroundColor,border:getComputedStyle(el).borderBottomColor,shadow:getComputedStyle(el).boxShadow}));
|
||||
const pane = await page.locator('.chrome-bar').evaluate(el=>getComputedStyle(el).backgroundColor);
|
||||
assert.equal(tab.background,pane);
|
||||
assert.equal(tab.border,'rgba(0, 0, 0, 0)');
|
||||
assert.equal(tab.shadow,'none');
|
||||
await page.locator(".line-history").waitFor();
|
||||
assert.match(await page.locator(".line-history").getAttribute("title"), /Line 5 · UI test/);
|
||||
await page.keyboard.type("x");
|
||||
await page.locator(".line-history").waitFor({ state: "hidden" });
|
||||
await page.keyboard.press("Control+z");
|
||||
await page.locator(".line-history").waitFor();
|
||||
|
||||
for (const theme of ["dark", "light"]) {
|
||||
await setTheme(theme);
|
||||
const tab = await page.locator(".tab.active").evaluate(el => ({ background: getComputedStyle(el).backgroundColor, border: getComputedStyle(el).borderBottomColor, shadow: getComputedStyle(el).boxShadow }));
|
||||
const pane = await page.locator(".chrome-bar").evaluate(el => getComputedStyle(el).backgroundColor);
|
||||
assert.equal(tab.background, pane);
|
||||
assert.equal(tab.border, "rgba(0, 0, 0, 0)");
|
||||
assert.equal(tab.shadow, "none");
|
||||
await line.hover();
|
||||
await page.screenshot({path:`.audit/ui-cards/writer-${theme}.png`});
|
||||
await page.getByRole('group',{name:'Document view'}).locator('button.current').press('ArrowRight');
|
||||
await page.locator('.md-page .reading').waitFor();
|
||||
const paragraph=page.locator('.md-page p').filter({hasText:'A second paragraph.'});
|
||||
await page.screenshot({ path: path.join(output, `writer-${theme}.png`) });
|
||||
await documentView().press("ArrowRight");
|
||||
await page.locator(".md-page .reading").waitFor();
|
||||
const paragraph = page.locator(".md-page p").filter({ hasText: "A second paragraph." });
|
||||
await paragraph.hover();
|
||||
assert.equal(await paragraph.evaluate(el=>getComputedStyle(el,'::before').width),'3px');
|
||||
assert.ok((await page.locator('.md-page table').boundingBox()).width<400);
|
||||
await page.screenshot({path:`.audit/ui-cards/read-${theme}.png`});
|
||||
await page.getByRole('group',{name:'Document view'}).locator('button.current').press('Home');
|
||||
assert.equal(await paragraph.evaluate(el => getComputedStyle(el, "::before").width), "3px");
|
||||
assert.ok((await page.locator(".md-page table").boundingBox()).width < 400);
|
||||
await page.screenshot({ path: path.join(output, `read-${theme}.png`) });
|
||||
await documentView().press("Home");
|
||||
}
|
||||
await page.getByRole('group',{name:'Editor layout'}).locator('button.current').press('Home');
|
||||
await page.locator('.monaco-editor').waitFor();
|
||||
await page.locator('.line-history').waitFor();
|
||||
await page.evaluate(()=>window.removeGit());
|
||||
await page.locator('.line-history').waitFor({state:'hidden'});
|
||||
await page.getByRole('group',{name:'Editor layout'}).locator('button.current').press('End');
|
||||
await page.getByRole('button',{name:'Hide outline',exact:true}).click();
|
||||
await page.setViewportSize({width:760,height:640});
|
||||
for(const theme of ['dark','light']) {
|
||||
await page.evaluate(theme=>document.documentElement.dataset.theme=theme,theme);
|
||||
const dimensions=await page.locator('.header-left .icon-btn').evaluateAll(els=>els.map(el=>({width:el.getBoundingClientRect().width,svg:el.querySelector('svg').getBoundingClientRect().width})));
|
||||
assert.ok(dimensions.every(size=>size.width>=28 && size.svg>=16),JSON.stringify(dimensions));
|
||||
assert.ok(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth));
|
||||
await page.screenshot({path:`.audit/ui-cards/narrow-${theme}.png`});
|
||||
await editorLayout().press("Home");
|
||||
await page.locator(".monaco-editor").waitFor();
|
||||
await page.locator(".line-history").waitFor();
|
||||
await page.evaluate(() => window.removeGit());
|
||||
await page.locator(".line-history").waitFor({ state: "hidden" });
|
||||
await editorLayout().press("End");
|
||||
await page.getByRole("button", { name: "Hide outline", exact: true }).click();
|
||||
await page.setViewportSize({ width: 760, height: 640 });
|
||||
for (const theme of ["dark", "light"]) {
|
||||
await setTheme(theme);
|
||||
const dimensions = await page.locator(".header-left .icon-btn").evaluateAll(els => els.map(el => ({ width: el.getBoundingClientRect().width, svg: el.querySelector("svg").getBoundingClientRect().width })));
|
||||
assert.ok(dimensions.every(size => size.width >= 28 && size.svg >= 16), JSON.stringify(dimensions));
|
||||
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth));
|
||||
await page.screenshot({ path: path.join(output, `narrow-${theme}.png`) });
|
||||
}
|
||||
assert.deepEqual(errors,[]);
|
||||
console.log('PASS: pane-aligned ribbon, compact square tables, focus-only tree border, joined tabs, Writer/Read hover marker, Git line slot lifecycle, both themes and narrow width');
|
||||
} finally {await browser.close();}
|
||||
console.log("PASS: pane-aligned ribbon, compact square tables, focus-only tree border, joined tabs, Writer/Read hover marker, Git line slot lifecycle, both themes and narrow width");
|
||||
}, { timeout: 30000 });
|
||||
|
||||
Reference in New Issue
Block a user