flaky test passes locally but fails in CI: debugging
Debugs tests that pass locally and fail in CI: environment diffing. Use when the failure is CI-only and intermittent. Not for consistent CI failures.
TL;DR
CI-only flakes come from slower, smaller, or different environments. Reproduce CI conditions locally (same container, fewer CPUs, headless), then fix the timing or resource assumption.
Error
(Not an error; a debugging workflow. Symptom: green locally, red sometimes in CI.)Steps
- Run the test 20 times locally:
for i in $(seq 20); do npx playwright test file.spec.ts; done. Expected: if it never flakes locally, it is environmental. - Run in the CI container image locally. Expected: reproduces container-specific flakes.
- Throttle CPU: run with fewer workers or CPU limits to simulate slow CI. Expected: timing flakes appear.
- Check the usual suspects: timezone, locale, fonts, screen size, seeded data. Expected: one differs.
- Fix the assumption (explicit waits, pinned TZ, hermetic data) and verify with 20 CI runs. Expected: the flake is gone where it lived.
When to use
- Flaky only in CI, never locally.
- Intermittent, not consistent.
When not to use
- Consistent CI failure (environment difference, not flake).
- Flaky everywhere (test bug; debug locally).
Tool compatibility
- Any framework; docker for CI reproduction.
Variant phrasings
Test flaky in CI only
The classic report; environment diffing is the method.
Works on my machine test failure
The joke with a real debugging procedure behind it.
Why it happens
CI runners are slower, smaller, and differently configured than laptops. Tests with implicit timing or resource assumptions break there first.
Edge cases
--repeat-eachin Playwright automates the 20-run loop.- Record CI timings; flakes cluster on slow runs.
- Do not "fix" by raising timeouts globally; fix the assumption.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst3UcqS0vlq2ppkMBsZkOsw
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.