playwright test.only accidentally committed: how to detect in CI
Shows how to catch an accidentally committed Playwright test.only in CI using the --forbid-only flag, plus a lint rule to catch it before commit. Use it when setting up CI guards against focused tests. Not for debugging why only one test ran locally, or for choosing a test selection strategy.
TL;DR
Run your CI test command with the --forbid-only flag; any committed test.only (or describe.only) fails the run immediately. Add it to the CI script once and it guards every future PR. Pair it with a lint rule so editors catch it before commit.
Problem
A test.only slipped into a merged PR, so CI ran one test, reported green, and the rest of the suite never executed.
Steps
- Add
--forbid-onlyto the CI test command:npx playwright test --forbid-only. Expected: the command exits non-zero if any focused test exists. - Push a branch containing a
test.onlyand watch CI fail fast. Expected: CI fails with a forbid-only error before running any tests. - Add the
no-focused-testrule fromeslint-plugin-playwrightto your lint config so it is caught locally too. Expected: the linter flagstest.onlylines on the next run. - Remove the committed
.onlyand merge. Expected: the full suite runs green in CI.
When to use
- Setting up a CI pipeline for a Playwright suite.
- A focused test was committed before and you want it to never happen again.
- You want a fast, zero-maintenance guard rather than code review vigilance.
When not to use
- Debugging why only one test runs on your machine (just delete the
.only). - Choosing which tests to run per PR (use projects, tags, or grep for that).
- You use a different runner where
--forbid-onlydoes not exist.
Tool compatibility
- Playwright 1.40 through 1.5x (
--forbid-onlyis a long-standing CLI flag). eslint-plugin-playwright1.x and 2.x for theno-focused-testrule.
Variant phrasings
how to block test.only in playwright CI pipeline
Same answer: --forbid-only on the CI command.
detect focused tests before merge playwright
Same guard; the lint rule adds a pre-commit layer on top.
Why it happens
test.only is meant for local debugging, but nothing stops it from being committed. Without a guard, CI happily runs the single focused test, reports green, and nobody notices the other 500 tests never ran.
Edge cases
--forbid-onlyin the shared npm script also affects local runs; keep it in the CI yaml command or gate it behind an env check.- A
test.onlyinside a skipped file still trips the flag; remove all of them. - Monorepo with several configs: the flag must be on every
playwright testinvocation.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_VHlpjJaKP7eyHRvd5MbsmQ
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.