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
87 lines
4 KiB
TypeScript
87 lines
4 KiB
TypeScript
// Early Size Test - Verifies GetClientSize() returns reasonable values before Show()
|
|
// This reproduces KiCad's pattern where GetClientSize() is called in the constructor.
|
|
//
|
|
// Determinism: no waitForTimeout. Readiness via waitForWxApp (loud). The app emits its
|
|
// early client/frame size logs and a terminal PASS/FAIL during init; instead of sleeping
|
|
// 500ms we poll for the terminal PASS/FAIL marker, which guarantees every size log the
|
|
// assertions parse is already present. Static loaded/result states use stableShot.
|
|
import { test, expect, waitForWxApp } from './utils/fixtures';
|
|
import { stableShot } from './utils/element-tracker';
|
|
|
|
test.describe('Early GetClientSize() Tests', () => {
|
|
|
|
test('Early size test app loads successfully', async ({ page, testLogger }) => {
|
|
await page.goto('/standalone/earlysize/earlysize_test.html');
|
|
await waitForWxApp(page);
|
|
|
|
await stableShot(page, 'earlysize-01-loaded.png', { fullPage: true });
|
|
|
|
const hasStartup = testLogger.consoleLogs.some(l => l.includes('[EARLYSIZE_TEST] Early size test app started'));
|
|
|
|
expect(hasStartup, 'Startup log should be present').toBe(true);
|
|
expect(testLogger.errors.filter(e => !e.includes('favicon'))).toHaveLength(0);
|
|
});
|
|
|
|
test('GetClientSize() returns reasonable values before Show()', async ({ page, testLogger }) => {
|
|
await page.goto('/standalone/earlysize/earlysize_test.html');
|
|
await waitForWxApp(page);
|
|
|
|
// Wait for the app to finish initialization: it logs a terminal PASS/FAIL result once
|
|
// its early size checks are done, which implies the client/frame size logs are present.
|
|
await expect
|
|
.poll(
|
|
() =>
|
|
testLogger.consoleLogs.some(
|
|
l => l.includes('[EARLYSIZE_TEST] PASS') || l.includes('[EARLYSIZE_TEST] FAIL'),
|
|
),
|
|
{ message: 'earlysize test should log its terminal PASS/FAIL result' },
|
|
)
|
|
.toBe(true);
|
|
|
|
await stableShot(page, 'earlysize-02-result.png', { fullPage: true });
|
|
|
|
// Check for early client size log
|
|
const clientSizeLogs = testLogger.consoleLogs.filter(l => l.includes('[EARLYSIZE_TEST] Early client size:'));
|
|
expect(clientSizeLogs.length).toBeGreaterThan(0);
|
|
|
|
// Parse the early client size
|
|
const clientSizeLog = clientSizeLogs[0];
|
|
const clientMatch = clientSizeLog.match(/Early client size: (\d+)x(\d+)/);
|
|
expect(clientMatch, 'Client size log should contain dimensions').not.toBeNull();
|
|
|
|
if (clientMatch) {
|
|
const clientWidth = parseInt(clientMatch[1]);
|
|
const clientHeight = parseInt(clientMatch[2]);
|
|
|
|
// The key assertion: early client size should NOT be 20x20 or similar tiny values
|
|
// This is the bug we're testing for - KiCad gets 20x20 here
|
|
expect(clientWidth, `Early client width should be > 100 (got ${clientWidth})`).toBeGreaterThan(100);
|
|
expect(clientHeight, `Early client height should be > 100 (got ${clientHeight})`).toBeGreaterThan(100);
|
|
}
|
|
|
|
// Check for early frame size log
|
|
const frameSizeLogs = testLogger.consoleLogs.filter(l => l.includes('[EARLYSIZE_TEST] Early frame size:'));
|
|
expect(frameSizeLogs.length).toBeGreaterThan(0);
|
|
|
|
// Parse the early frame size
|
|
const frameSizeLog = frameSizeLogs[0];
|
|
const frameMatch = frameSizeLog.match(/Early frame size: (\d+)x(\d+)/);
|
|
expect(frameMatch, 'Frame size log should contain dimensions').not.toBeNull();
|
|
|
|
if (frameMatch) {
|
|
const frameWidth = parseInt(frameMatch[1]);
|
|
const frameHeight = parseInt(frameMatch[2]);
|
|
|
|
// Frame size should also be reasonable
|
|
expect(frameWidth, `Early frame width should be > 100 (got ${frameWidth})`).toBeGreaterThan(100);
|
|
expect(frameHeight, `Early frame height should be > 100 (got ${frameHeight})`).toBeGreaterThan(100);
|
|
}
|
|
|
|
// Check for PASS/FAIL result
|
|
const passLog = testLogger.consoleLogs.some(l => l.includes('[EARLYSIZE_TEST] PASS'));
|
|
const failLog = testLogger.consoleLogs.some(l => l.includes('[EARLYSIZE_TEST] FAIL'));
|
|
|
|
expect(failLog, 'Should not have FAIL log').toBe(false);
|
|
expect(passLog, 'Should have PASS log').toBe(true);
|
|
});
|
|
});
|