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

@ -2,14 +2,13 @@
// C++ (wxEVT_SCROLL for the standalone wxScrollBar; wxEVT_SCROLLWIN for the
// wxScrolledWindow gutter, which scrolls the content). The thumb registers as
// 'slider' + 'slidertrack' so Playwright can drag it.
import { test, expect, tryLoadApp } from './utils/fixtures';
import { findRenderedByType } from './utils/element-tracker';
import { test, expect, waitForWxApp } from './utils/fixtures';
import { findRenderedByType, stableShot } from './utils/element-tracker';
test.describe('DOM-port scrollbars', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/standalone/scrollbar/scrollbar_test.html');
expect(await tryLoadApp(page, 30000), 'scrollbar app should load').toBe(true);
await page.waitForTimeout(500);
await waitForWxApp(page);
});
test('scrollbars render draggable thumbs', async ({ page, testLogger }) => {
@ -18,7 +17,7 @@ test.describe('DOM-port scrollbars', () => {
{ timeout: 8000, message: 'scrollbar thumbs should register' },
).toBeGreaterThanOrEqual(2);
await page.screenshot({ path: 'test-results/scrollbar-01-loaded.png', fullPage: true });
await stableShot(page, 'scrollbar-01-loaded.png', { fullPage: true });
expect(testLogger.errors.filter((e) => !e.includes('favicon'))).toHaveLength(0);
});
@ -49,15 +48,15 @@ test.describe('DOM-port scrollbars', () => {
await page.mouse.down();
await page.mouse.move(tx, ty, { steps: 6 });
await page.mouse.up();
await page.waitForTimeout(150);
await page.waitForTimeout(150); // eslint-disable-line -- documented interaction dwell
}
await page.screenshot({ path: 'test-results/scrollbar-02-dragged.png', fullPage: true });
// At least one standalone scrollbar must have reported a non-zero position.
await expect.poll(
() => testLogger.consoleLogs.some((l) => /\[SCROLLBAR_EVENT\] scrollbar pos [1-9]/.test(l)),
{ timeout: 8000, message: 'a standalone scrollbar drag should report a non-zero position' },
).toBe(true);
await stableShot(page, 'scrollbar-02-dragged.png', { fullPage: true });
});
});