test(determinism): deterministic waits + stableShot screenshots; drop blind sleeps/ifs/retries

Make the Playwright e2e + kicad suites deterministic so screenshot flake stops
tracing to timing races.

- Blind page.waitForTimeout -> condition waits (expect.poll, web-first
  assertions, waitUntil) + readiness helpers (waitForWxApp, waitForCanvasApp).
  Remaining sleeps are documented interaction dwells (annotated).
- Defensive "if element exists" branches -> loud asserts; label-fallback chains
  -> normalized clickMenuItemByText. First-run wizard for/if loops removed by
  seeding calculator/gerbview/pcbnew HTMLs.
- Screenshots: new stableShot(page, name) settles the render in-page (canvas
  hash over rAF) then writes a raw PNG to test-results/ for the existing offline
  gate (tools/screenshots vs baseline-screenshots). Replaces toHaveScreenshot,
  which did inline compare + its own baselines and had decoupled the specs from
  the real gate. scale:'css' pinned.
- retries: 0 in both configs.
- Guard: tests/tools/lint-determinism.ts (npm run lint:determinism) bans blind
  sleeps / toHaveScreenshot / inline retries / swallowed catches in specs;
  documented exceptions carry a marker. Rules in tests/TESTING.md.

Assertions, coverage, and renders unchanged (semantic-equivalence reviewed;
captures pixel-identical modulo inherent timer/timestamp/3d-raytrace variance).
Both suites green at retries:0 (e2e 340, kicad 92); ~35-61% faster.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BVX1pHMvRPYHdp6ZfEawrk
This commit is contained in:
Viktor Vaczi 2026-07-07 10:50:24 +02:00
commit 4c3a4cacd4
102 changed files with 2867 additions and 3407 deletions

View file

@ -1,26 +1,23 @@
// wxPopupWindow Tests - Transient popups like KiCad toolbar palettes
import { test, expect, tryLoadApp } from './utils/fixtures';
import { findByLabel, clickByLabel } from './utils/element-tracker';
import { test, expect, waitForWxApp } from './utils/fixtures';
import { findByLabel, clickByLabel, stableShot } from './utils/element-tracker';
test.describe('wxPopupWindow Tests', () => {
test('Popup test app loads successfully', async ({ page, testLogger }) => {
await page.goto('/standalone/popup/popup_test.html');
const loaded = await tryLoadApp(page);
await waitForWxApp(page);
await page.screenshot({ path: 'test-results/popup-01-loaded.png', fullPage: true });
await stableShot(page, 'popup-01-loaded.png', { fullPage: true });
expect(loaded, 'Popup app should load').toBe(true);
expect(testLogger.errors.filter(e => !e.includes('favicon'))).toHaveLength(0);
});
test('Status popup button exists', async ({ page, testLogger }) => {
await page.goto('/standalone/popup/popup_test.html');
const loaded = await tryLoadApp(page);
expect(loaded, 'App should load').toBe(true);
await waitForWxApp(page);
await page.waitForTimeout(500);
await page.screenshot({ path: 'test-results/popup-02-status.png', fullPage: true });
await stableShot(page, 'popup-02-status.png', { fullPage: true });
// App loaded successfully - verify no errors
expect(testLogger.errors.filter(e => !e.includes('favicon'))).toHaveLength(0);
@ -32,13 +29,12 @@ test.describe('wxPopupWindow Tests', () => {
// visible/clickable), PASSES after.
test('Tool palette opens and a tool button is clickable', async ({ page, testLogger }) => {
await page.goto('/standalone/popup/popup_test.html');
expect(await tryLoadApp(page), 'App should load').toBe(true);
await waitForWxApp(page);
// Open the transient palette (wxPopupTransientWindow::Popup()).
expect(await clickByLabel(page, 'Show Tool Palette'),
'"Show Tool Palette" button should be clickable').toBe(true);
await page.waitForTimeout(500);
await page.screenshot({ path: 'test-results/popup-03-palette-open.png', fullPage: true });
await stableShot(page, 'popup-03-palette-open.png', { fullPage: true });
// The palette must actually render as an overlay: its tool buttons (T1..T9) become visible.
const t1 = await findByLabel(page, 'T1', { visible: true });
@ -46,62 +42,49 @@ test.describe('wxPopupWindow Tests', () => {
// And clicking a tool must fire its handler (logged via EM_ASM console.log in popup_test.cpp).
expect(await clickByLabel(page, 'T1', { visible: true }), 'palette tool T1 should be clickable').toBe(true);
await page.waitForTimeout(300);
expect(
testLogger.consoleLogs.some(l => l.includes('[POPUP] Tool 1 clicked')),
'clicking palette tool T1 should fire its handler'
await expect.poll(
() => testLogger.consoleLogs.some(l => l.includes('[POPUP] Tool 1 clicked')),
{ message: 'clicking palette tool T1 should fire its handler' }
).toBe(true);
});
// The palette is transient: clicking outside should dismiss it.
test('Tool palette dismisses on outside click', async ({ page }) => {
await page.goto('/standalone/popup/popup_test.html');
expect(await tryLoadApp(page), 'App should load').toBe(true);
await waitForWxApp(page);
expect(await clickByLabel(page, 'Show Tool Palette')).toBe(true);
await page.waitForTimeout(500);
expect(await findByLabel(page, 'T1', { visible: true }),
'palette should open before testing dismiss').not.toBeNull();
await expect.poll(
async () => await findByLabel(page, 'T1', { visible: true }),
{ message: 'palette should open before testing dismiss' }
).not.toBeNull();
// Click far from the palette to dismiss the transient popup.
await page.mouse.click(600, 500);
await page.waitForTimeout(400);
await page.screenshot({ path: 'test-results/popup-03-palette-dismissed.png', fullPage: true });
await stableShot(page, 'popup-03-palette-dismissed.png', { fullPage: true });
expect(await findByLabel(page, 'T1', { visible: true }),
'palette should be dismissed (T1 no longer visible) after an outside click').toBeNull();
});
test('Color picker button exists', async ({ page, testLogger }) => {
await page.goto('/standalone/popup/popup_test.html');
const loaded = await tryLoadApp(page);
expect(loaded, 'App should load').toBe(true);
await waitForWxApp(page);
await page.waitForTimeout(500);
await page.screenshot({ path: 'test-results/popup-04-color.png', fullPage: true });
expect(loaded, 'Color picker button should exist').toBe(true);
await stableShot(page, 'popup-04-color.png', { fullPage: true });
});
test('Positioning buttons exist', async ({ page, testLogger }) => {
await page.goto('/standalone/popup/popup_test.html');
const loaded = await tryLoadApp(page);
expect(loaded, 'App should load').toBe(true);
await waitForWxApp(page);
await page.waitForTimeout(500);
await page.screenshot({ path: 'test-results/popup-05-positioning.png', fullPage: true });
expect(loaded, 'Positioning buttons should exist').toBe(true);
await stableShot(page, 'popup-05-positioning.png', { fullPage: true });
});
test('Event log panel exists', async ({ page, testLogger }) => {
await page.goto('/standalone/popup/popup_test.html');
const loaded = await tryLoadApp(page);
expect(loaded, 'App should load').toBe(true);
await waitForWxApp(page);
await page.waitForTimeout(500);
await page.screenshot({ path: 'test-results/popup-06-log.png', fullPage: true });
expect(loaded, 'Event log should exist').toBe(true);
await stableShot(page, 'popup-06-log.png', { fullPage: true });
});
});