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,43 +1,36 @@
|
||||
// Background image position and size: menu choices, a stable surface under overflow, persistence, keyboard choice, both themes, narrow settings.
|
||||
import assert from 'node:assert/strict';
|
||||
import { createRequire } from 'node:module';
|
||||
import { mkdir, writeFile } from 'node:fs/promises';
|
||||
const { chromium } = createRequire(import.meta.url)(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: 1100, height: 780 } });
|
||||
await context.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
let sequence = 0;
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: 'main' }, currentWebview: { label: 'main' } },
|
||||
transformCallback: () => ++sequence, unregisterCallback: () => {},
|
||||
invoke: async (command) => {
|
||||
if (command === 'plugins_snapshot') return { root: 'C:/plugins', plugins: [] };
|
||||
if (command === 'plugin:window|is_maximized') return false;
|
||||
if (command === 'plugin:event|listen') return ++sequence;
|
||||
return null;
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
||||
});
|
||||
const main = await context.newPage(), settings = await context.newPage();
|
||||
const origin = process.env.SMOKE_URL || 'http://127.0.0.1:5187';
|
||||
const screenshots = [];
|
||||
await mkdir('output/todo-background', { recursive: true });
|
||||
try {
|
||||
await main.goto(origin);
|
||||
await settings.goto(origin + '/?settingsWindow=true');
|
||||
import { writeFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
|
||||
|
||||
// The image is painted on .workarea-background, not on the empty tab (src/lib/layout/Workbench.svelte:1258, 1543).
|
||||
await runSmoke('appearance/backgroundLayout', async ({ browser }) => {
|
||||
const output = await outputDir('appearance/backgroundLayout');
|
||||
const context = await browser.newContext({ viewport: { width: 1100, height: 780 } });
|
||||
await mockTauri(context, {
|
||||
commands: () => ({
|
||||
plugins_snapshot: () => ({ root: 'C:/plugins', plugins: [] }),
|
||||
'plugin:window|is_maximized': () => false,
|
||||
}),
|
||||
});
|
||||
const main = await openPage(context), settings = await openPage(context);
|
||||
const screenshots = [];
|
||||
await main.goto(smokeUrl);
|
||||
await main.locator('.empty').waitFor();
|
||||
await settings.goto(smokeUrl + '/?settingsWindow=true');
|
||||
await settings.getByRole('button', { name: 'Appearance', exact: true }).click();
|
||||
const png = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jM1sAAAAASUVORK5CYII=', 'base64');
|
||||
await settings.getByLabel('Background image file', { exact: true }).setInputFiles({ name: 'image.png', mimeType: 'image/png', buffer: png });
|
||||
await main.waitForFunction(() => getComputedStyle(document.querySelector('.empty')).backgroundImage.includes('blob:'));
|
||||
await main.waitForFunction(() => getComputedStyle(document.querySelector('.workarea-background')).backgroundImage.includes('blob:'));
|
||||
for (const [control, choice] of [['Image position', 'Top left'], ['Image size', 'Actual size']]) {
|
||||
const button = settings.getByRole('button', { name: control, exact: true });
|
||||
await button.click();
|
||||
await settings.getByRole('menuitemradio', { name: choice, exact: true }).click();
|
||||
assert.equal(await button.evaluate(node => node === document.activeElement), true);
|
||||
}
|
||||
await main.waitForFunction(() => getComputedStyle(document.querySelector('.empty')).backgroundPosition.endsWith('0% 0%'));
|
||||
const layout = () => main.locator('.empty').evaluate(node => {
|
||||
await main.waitForFunction(() => getComputedStyle(document.querySelector('.workarea-background')).backgroundPosition.endsWith('0% 0%'));
|
||||
const layout = () => main.locator('.workarea-background').evaluate(node => {
|
||||
const style = getComputedStyle(node), box = node.getBoundingClientRect();
|
||||
return { position: style.backgroundPosition, size: style.backgroundSize, width: box.width, height: box.height };
|
||||
});
|
||||
@@ -49,13 +42,13 @@ try {
|
||||
assert.deepEqual(await layout(), before, 'Overflowing content does not resize or reposition the image surface');
|
||||
await main.reload();
|
||||
await main.locator('.empty').waitFor();
|
||||
await main.waitForFunction(() => getComputedStyle(document.querySelector('.empty')).backgroundImage.includes('blob:'));
|
||||
await main.waitForFunction(() => getComputedStyle(document.querySelector('.workarea-background')).backgroundImage.includes('blob:'));
|
||||
assert.equal((await layout()).position, before.position);
|
||||
assert.equal((await layout()).size, before.size);
|
||||
await settings.getByRole('button', { name: 'Image position', exact: true }).click();
|
||||
await settings.keyboard.press('End');
|
||||
await settings.keyboard.press('Enter');
|
||||
await main.waitForFunction(() => getComputedStyle(document.querySelector('.empty')).backgroundPosition.endsWith('100% 100%'));
|
||||
await main.waitForFunction(() => getComputedStyle(document.querySelector('.workarea-background')).backgroundPosition.endsWith('100% 100%'));
|
||||
for (const mode of ['light', 'dark']) {
|
||||
await settings.evaluate(async mode => {
|
||||
const appearance = await import('/src/lib/theme/appearance.ts');
|
||||
@@ -65,12 +58,12 @@ try {
|
||||
await main.waitForFunction(mode => document.documentElement.dataset.theme === mode, mode);
|
||||
for (const width of [1100, 360]) {
|
||||
await settings.setViewportSize({ width, height: 700 });
|
||||
const file = `output/todo-background/settings-${mode}-${width}.png`;
|
||||
const file = path.join(output, `settings-${mode}-${width}.png`);
|
||||
await settings.screenshot({ path: file }); screenshots.push(file);
|
||||
const pane = settings.locator('.content');
|
||||
assert.equal(await pane.evaluate(node => node.scrollWidth <= node.clientWidth + 1), true);
|
||||
assert.equal(await settings.locator('.content').evaluate(node => node.scrollWidth <= node.clientWidth + 1), true);
|
||||
}
|
||||
}
|
||||
await writeFile('output/todo-background-report.json', JSON.stringify({ card: 'ab7b1a06-fd5a-4b74-aaa1-da64eafdf71c', checks: ['Alignment and sizing choices persist across reload and windows', 'Overflow does not resize the background surface', 'Keyboard choice and focus return', 'Both themes and narrow settings'], screenshots, native: 'Desktop visual acceptance remains pending.' }, null, 2));
|
||||
await writeFile(path.join(output, 'report.json'), JSON.stringify({ card: 'ab7b1a06-fd5a-4b74-aaa1-da64eafdf71c', checks: ['Alignment and sizing choices persist across reload and windows', 'Overflow does not resize the background surface', 'Keyboard choice and focus return', 'Both themes and narrow settings'], screenshots, native: 'Desktop visual acceptance remains pending.' }, null, 2));
|
||||
assert.deepEqual([...main.errors, ...settings.errors], []);
|
||||
console.log('PASS: background alignment, size, stable surface, persistence, keyboard, both themes, narrow settings.');
|
||||
} finally { await browser.close(); }
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user