Isolate test data and release checks
Keep each test independent
A fresh browser context isolates cookies and browser storage between tests; it does not reset a shared database or external queue. Use per-test synthetic data, an independent service fixture or a reset protocol that owns only lab data. Never copy a real login session into a test archive. Configure a reviewed local server and exact base URL; do not attach to an unknown existing process. Disable external egress at the environment boundary. Route interception is useful for deterministic responses, but it is not a general security sandbox.
import { defineConfig } from '@playwright/test';export default defineConfig({ testDir: '.', testMatch:'*.spec.mjs', timeout:15000, expect:{timeout:5000}, workers:1, retries:0, use:{baseURL:'http://127.0.0.1:4179', browserName:'chromium', viewport:{width:1024,height:800}, deviceScaleFactor:1, locale:'en-US', reducedMotion:'reduce', serviceWorkers:'block', trace:'retain-on-failure', video:'off'}, webServer:{command:'npm run preview -- --host 127.0.0.1 --port 4179 --strictPort', url:'http://127.0.0.1:4179', reuseExistingServer:false, timeout:30000}});Build the reviewed source first with npm run build, then run the installed Playwright Test executable. The config starts preview, rejects an occupied port and bounds test and startup time. Use one worker for the first baseline; scale only after proving isolation. No retries by default so an intermittent failure is visible. A CI retry may collect diagnostic evidence but should not erase a flaky result. Vite preview is only a local build smoke server, not a production hosting recommendation.
Prove the mock and context boundaries
import { test, expect } from '@playwright/test';test('one context does not inherit another draft', async ({browser,baseURL}) => { const first = await browser.newContext({baseURL}); const second = await browser.newContext({baseURL}); try { const a = await first.newPage(); const b = await second.newPage(); await a.goto('/tickets/new'); await a.evaluate(() => localStorage.setItem('test-draft','synthetic')); await a.reload(); expect(await a.evaluate(() => localStorage.getItem('test-draft'))).toBe('synthetic'); await b.goto('/tickets/new'); expect(await b.evaluate(() => localStorage.getItem('test-draft'))).toBeNull(); } finally { await first.close(); await second.close(); }});The test demonstrates browser-storage isolation, not application persistence: the repair app itself intentionally does not store drafts. For actual persistence, test the product contract after reload and logout. For permission-aware UI, test both visible affordances and an independently authorized server rejection; a hidden button or a mocked 403 cannot prove server authorization. For SSR, verify server output, hydration errors and interaction after hydration in a separate real SSR fixture (see earlier chapters). This client-only app cannot establish SSR behavior.
Make release decisions from evidence
export function canRelease(report) { const required = ['build','unit','browser','visualReview','accessibilityReview','serverAuthorization']; return required.every(key => report[key] === 'passed') && report.unresolvedFlakes === 0;}This pure example models a fictional release policy. Missing or skipped gates block release; a clean mock-only browser suite cannot mark serverAuthorization passed. CI should install reviewed locked dependencies in an isolated runner, run unit tests, build, run smoke journeys across supported engines, compare approved visual baselines and require human review where applicable. Keep trace, screenshots and logs restricted, since they can contain page text, network headers or synthetic identifiers; do not upload real secrets or recordings to public storage. Use local trace viewer and limited retention. Record browser/OS/font versions and separate first-run failure from retry success. Practice: supply a report with all gates passed except serverAuthorization, and verify that release is blocked. A passing policy function does not establish that its input evidence is genuine.