pcbjam/tests/playwright-asyncify.config.ts
Viktor Vaczi b270507505 fix(tests): keep test-results across CI suites; loud pipeline alert
The screenshot report went silent on green CI runs. CI runs four sequential
`playwright test` invocations (wx, asyncify, kicad, perf) that all default their
outputDir to `test-results`; Playwright clears the whole outputDir at the start
of every run, so each suite wiped the previous suite's screenshots. By the time
`compare` ran, only perf-*.json remained -> all 354 baselines read as "removed"
-> the no-render guard stayed silent.

- Gate Playwright's outputDir off test-results/ in CI only
  (process.env.CI ? 'pw-artifacts/<suite>' : 'test-results') in the wx / asyncify
  / kicad configs, so the committed-baseline screenshots (page.screenshot to
  'test-results/...') accumulate in test-results/ across the suites for compare.
  Local single-suite behavior is unchanged.
- post-discord: replace the silent no-render guard with a loud, image-less
  pipeline alert ("No screenshots produced this run") when 0 render; genuine
  partial removals still post as the normal capped REMOVED list.
- gitignore pw-artifacts/; upload tests/pw-artifacts/** as a CI artifact.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-02 09:20:35 +02:00

89 lines
2.9 KiB
TypeScript

import { defineConfig, devices } from '@playwright/test';
import { execSync } from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
// Runs the Asyncify race-condition red-green harness (tests/asyncify/) in both
// Firefox and system Chrome. Mirrors playwright-coroutine.config.ts (Chrome must
// be --headed on ARM Mac; Firefox headless OK).
const PORT_FILE = path.join(__dirname, '.test-port-asyncify');
function findFreePort(): number {
try {
const result = execSync(
'python3 -c "import socket; s=socket.socket(); s.bind((\'\',0)); print(s.getsockname()[1]); s.close()"',
{ encoding: 'utf-8' }
);
return parseInt(result.trim());
} catch {
return 9100 + Math.floor(Math.random() * 800);
}
}
// Same port-pinning scheme as playwright-kicad.config.ts: the main runner picks a
// fresh port and writes the file before workers spawn; workers always reuse it.
function resolvePort(): number {
const isMainRunner = process.argv.slice(2).includes('test');
if (!isMainRunner) {
try {
const existing = parseInt(fs.readFileSync(PORT_FILE, 'utf-8').trim(), 10);
if (existing > 0 && existing < 65536) return existing;
} catch { /* fall through */ }
}
const port = findFreePort();
fs.writeFileSync(PORT_FILE, port.toString());
return port;
}
const port = resolvePort();
export default defineConfig({
globalSetup: './global-setup.ts',
testDir: './asyncify',
testMatch: /asyncify-races.*\.spec\.ts$/,
// See playwright.config.ts: keep CI's outputDir cleanup off test-results/ (this run is
// what would otherwise wipe the wx screenshots inside `npm run test`).
outputDir: process.env.CI ? 'pw-artifacts/asyncify' : 'test-results',
fullyParallel: false, // one heavy WASM app at a time
forbidOnly: !!process.env.CI,
retries: 0,
workers: 1,
reporter: 'html',
timeout: 120000,
use: {
baseURL: `http://localhost:${port}`,
trace: 'retain-on-failure',
screenshot: 'only-on-failure',
},
projects: [
{
// Firefox: headless, reliable on ARM Mac.
name: 'firefox',
use: { ...devices['Desktop Firefox'], viewport: { width: 1280, height: 720 } },
},
{
// System Chrome (real V8) — run via: npm run test:asyncify:chrome (must be --headed).
name: 'chromium',
use: {
channel: 'chrome',
viewport: { width: 1280, height: 720 },
permissions: ['clipboard-read', 'clipboard-write'],
},
},
{
// WebKit (Safari's engine) — headless OK on macOS. Project policy: every spec must be
// green in all three engines (Firefox + Chrome + Safari). Run via npm run test:asyncify:safari.
name: 'webkit',
use: { ...devices['Desktop Safari'], viewport: { width: 1280, height: 720 } },
},
],
webServer: {
command: `npx serve apps -p ${port} -c ../serve.json`,
port: port,
reuseExistingServer: !process.env.CI,
},
});