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,44 +1,36 @@
|
||||
import { createRequire } from 'node:module';
|
||||
import { mkdir } from 'node:fs/promises';
|
||||
// Browser settings choice menus: keyboard selection and dismissal, saving, long profile lists, both themes, narrow layout, and cleanup.
|
||||
import assert from 'node:assert/strict';
|
||||
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 page = await browser.newPage({ viewport: { width: 1100, height: 850 } });
|
||||
const errors = [];
|
||||
page.on('pageerror', error => errors.push(error.message));
|
||||
await page.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const snapshot = {
|
||||
profiles: [{ id: 'user', name: 'Personal' }, { id: 'work', name: 'Work' }], tabs: [], bookmarks: [],
|
||||
settings: { search: 'duckduckgo', adblock: true, linkDestination: 'internal', personalRules: '', homepage: '', filterLists: [] },
|
||||
};
|
||||
window.browserMenuTest = { snapshot, calls: [] };
|
||||
let sequence = 0;
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: 'settings-main' }, currentWebview: { label: 'settings-main' } },
|
||||
transformCallback: () => ++sequence, unregisterCallback: () => {},
|
||||
invoke: async (command, args = {}) => {
|
||||
if (command === 'plugin:event|listen') return args.handler;
|
||||
if (command === 'plugin:event|unlisten') return;
|
||||
if (command === 'browser_connect') return 'menu-session';
|
||||
if (command === 'browser_stop' || command === 'plugins_release') return;
|
||||
if (command === 'plugins_snapshot') return { root: 'test', plugins: [] };
|
||||
if (command.startsWith('plugin:window|')) return false;
|
||||
if (command !== 'browser_request') throw Error('Unhandled IPC: ' + command);
|
||||
const details = args.args || {};
|
||||
window.browserMenuTest.calls.push({ command: args.command, ...details });
|
||||
if (args.command === 'webData') return { profileId: details.profileId, cookies: [], history: [] };
|
||||
if (args.command === 'settings') Object.assign(snapshot.settings, details);
|
||||
return structuredClone(snapshot);
|
||||
import path from 'node:path';
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
|
||||
|
||||
await runSmoke('browser/settingsMenus', async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
label: 'settings-main',
|
||||
commands: test => {
|
||||
const snapshot = {
|
||||
profiles: [{ id: 'user', name: 'Personal' }, { id: 'work', name: 'Work' }], tabs: [], bookmarks: [],
|
||||
settings: { search: 'duckduckgo', adblock: true, linkDestination: 'internal', personalRules: '', homepage: '', filterLists: [] },
|
||||
};
|
||||
// `requests` records browser requests; `calls` records every IPC command.
|
||||
Object.assign(test, { snapshot, requests: [] });
|
||||
return {
|
||||
browser_connect: () => 'menu-session',
|
||||
plugins_snapshot: () => ({ root: 'test', plugins: [] }),
|
||||
'plugin:window|is_maximized': () => false,
|
||||
browser_request: ({ command, args = {} }) => {
|
||||
test.requests.push({ command, ...args });
|
||||
if (command === 'webData') return { profileId: args.profileId, cookies: [], history: [] };
|
||||
if (command === 'settings') Object.assign(snapshot.settings, args);
|
||||
return structuredClone(snapshot);
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
||||
});
|
||||
const menu = name => page.getByRole('menu', { name, exact: true });
|
||||
const trigger = name => page.getByRole('button', { name, exact: true });
|
||||
try {
|
||||
await mkdir('output/todo-menus', { recursive: true });
|
||||
await page.goto((process.env.SMOKE_URL || 'http://127.0.0.1:1420') + '/?settingsWindow=true');
|
||||
});
|
||||
const output = await outputDir('browser/settingsMenus');
|
||||
const shot = name => page.screenshot({ path: path.join(output, name) });
|
||||
const menu = name => page.getByRole('menu', { name, exact: true });
|
||||
const trigger = name => page.getByRole('button', { name, exact: true });
|
||||
await page.goto(smokeUrl + '/?settingsWindow=true');
|
||||
await trigger('Browser').click();
|
||||
await trigger('Search engine').waitFor();
|
||||
for (const mode of ['dark', 'light']) {
|
||||
@@ -49,7 +41,7 @@ try {
|
||||
await engines.waitFor();
|
||||
assert.equal(await engines.getByRole('menuitemradio', { name: 'DuckDuckGo' }).getAttribute('aria-checked'), 'true');
|
||||
assert.equal(await engines.evaluate(node => getComputedStyle(node).borderColor), 'rgba(0, 0, 0, 0)');
|
||||
await page.screenshot({ path: `output/todo-menus/search-${mode}.png` });
|
||||
await shot(`search-${mode}.png`);
|
||||
await page.keyboard.press('End');
|
||||
await page.keyboard.press('Space');
|
||||
assert.equal(await trigger('Search engine').innerText(), 'Bing');
|
||||
@@ -60,11 +52,11 @@ try {
|
||||
await trigger('Profile').focus();
|
||||
await page.keyboard.press('Space');
|
||||
await menu('Profile').waitFor();
|
||||
await page.screenshot({ path: `output/todo-menus/profile-${mode}.png` });
|
||||
await shot(`profile-${mode}.png`);
|
||||
await page.keyboard.press('ArrowDown');
|
||||
await page.keyboard.press('Enter');
|
||||
await page.waitForFunction(() => document.querySelector('button[aria-label="Profile"]')?.textContent === 'Work');
|
||||
await page.waitForFunction(() => window.browserMenuTest.calls.some(call => call.command === 'webData' && call.profileId === 'work'));
|
||||
await page.waitForFunction(() => window.__TEST__.requests.some(request => request.command === 'webData' && request.profileId === 'work'));
|
||||
await trigger('Profile').click();
|
||||
await page.keyboard.press('Home');
|
||||
await page.keyboard.press('Enter');
|
||||
@@ -72,24 +64,24 @@ try {
|
||||
await trigger('Search engine').click();
|
||||
const bounds = await engines.boundingBox();
|
||||
assert.ok(bounds.x >= 8 && bounds.x + bounds.width <= 512);
|
||||
await page.screenshot({ path: `output/todo-menus/narrow-${mode}.png` });
|
||||
await shot(`narrow-${mode}.png`);
|
||||
await page.keyboard.press('Escape');
|
||||
assert.equal(await trigger('Search engine').evaluate(node => node === document.activeElement), true);
|
||||
await page.setViewportSize({ width: 1100, height: 850 });
|
||||
}
|
||||
await trigger('Search engine').click();
|
||||
await menu('Search engine').getByRole('menuitemradio', { name: 'Google', exact: true }).click();
|
||||
assert.equal(await page.evaluate(() => window.browserMenuTest.calls.filter(call => call.command === 'settings').length), 0, 'A choice does not submit the form');
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.requests.filter(request => request.command === 'settings').length), 0, 'A choice does not submit the form');
|
||||
await trigger('Save browser settings').click();
|
||||
await page.waitForFunction(() => window.browserMenuTest.snapshot.settings.search === 'google');
|
||||
await page.evaluate(async () => { const { state } = await import('/src/lib/browser/client.ts'); const snapshot = window.browserMenuTest.snapshot; snapshot.profiles.push(...Array.from({ length: 60 }, (_, i) => ({ id: 'p' + i, name: 'Profile ' + i }))); state.set(structuredClone(snapshot)); });
|
||||
await page.waitForFunction(() => window.__TEST__.snapshot.settings.search === 'google');
|
||||
await page.evaluate(async () => { const { state } = await import('/src/lib/browser/client.ts'); const snapshot = window.__TEST__.snapshot; snapshot.profiles.push(...Array.from({ length: 60 }, (_, i) => ({ id: 'p' + i, name: 'Profile ' + i }))); state.set(structuredClone(snapshot)); });
|
||||
await page.setViewportSize({ width: 520, height: 700 });
|
||||
await trigger('Profile').click();
|
||||
const profiles = menu('Profile');
|
||||
assert.equal(await profiles.evaluate(node => node.scrollHeight > node.clientHeight), true, 'Long profile lists scroll');
|
||||
await page.keyboard.press('End');
|
||||
assert.equal(await profiles.getByRole('menuitemradio', { name: 'Profile 59', exact: true }).evaluate(node => node === document.activeElement), true);
|
||||
await page.screenshot({ path: 'output/todo-menus/profile-long-narrow.png' });
|
||||
await shot('profile-long-narrow.png');
|
||||
await page.keyboard.press('Escape');
|
||||
assert.equal(await trigger('Profile').evaluate(node => node === document.activeElement), true);
|
||||
await trigger('Profile').click();
|
||||
@@ -103,6 +95,5 @@ try {
|
||||
await trigger('Search engine').click();
|
||||
await trigger('General').click();
|
||||
assert.equal(await page.locator('.rs-menu').count(), 0, 'Leaving Browser closes the menu');
|
||||
assert.deepEqual(errors, []);
|
||||
console.log('PASS: browser choices, persistence, keyboard selection and dismissal, long profiles, both themes, narrow layout, and cleanup.');
|
||||
} finally { await browser.close(); }
|
||||
}, { viewport: { width: 1100, height: 850 }, timeout: 30000 });
|
||||
|
||||
Reference in New Issue
Block a user