Affected tests on pull request: how do you run only what changed, safely?
On this page
To run only the affected tests on a pull request, pick a subset by what changed, run it first for fast feedback, and still run the full suite before you trust the result. Selection saves minutes but it is a guess, and the cost of a wrong guess is a regression that merges.
This guide covers Playwright’s own option, tag-based selection from a diff, the changes that should force a full run, and a policy you can copy.
What does Playwright’s only-changed option do?
It runs the test files affected by changes in git. Playwright’s CI documentation shows a pull request job that runs the tests with --only-changed pointing at the base branch before the full suite. It describes the option as analyzing the dependency graph of your suites to find affected test files.
The documentation is direct about the limit. It says this “is a heuristic and might miss tests”, and that “it’s important that you always run the full test suite after the preliminary test run”. Read that as the design: the subset is a fast preliminary signal, not a replacement.
Practical note:
- The comparison needs git history. A shallow checkout cannot compare against the base branch, so fetch enough history.
Where does file-level selection miss?
It misses what it cannot see. Two developers who wrote about selecting tests in Playwright describe the gaps. One notes that the option “doesn’t track which modules or helpers were changed”, and explains why they preferred running everything in the affected scope. Another warns that “a feature folder doesn’t prove isolation”, so a folder-based mapping can still miss shared code, and says a full run after merge is still needed.
Typical misses:
| Change | Why a subset can miss it |
|---|---|
| Shared page object or helper | Tests import it indirectly or by string |
| Fixture or global setup | Every test depends on it, none names it |
| Config, environment variables | No import to follow |
| Dependency upgrade | The lock file is not a test file |
| Data or seed change | Tests depend on state, not code |
How does tag-based selection work?
You tag tests by area, map changed paths to areas from a git diff, and pass the tags to the runner. Both write-ups above use this: tests carry tags for a service or feature, a script reads the diff, and the result goes to --grep.
A simple version has three parts:
- A tag per area, such as
@checkoutor@search, added to the tests that cover it. - A mapping file from path patterns to tags.
- A fallback: if any changed path matches no pattern, or matches a shared pattern, run everything.
The fallback is the safety. Without it, any file you forgot to map is silently untested. Review the mapping file when you add a feature folder, and treat a tag with no tests as an error.
Which changes should always run every test?
Decide this once and write it down. A good default list:
- Shared helpers, page objects, fixtures and test configuration
- Application configuration and environment files
- Dependency and lock file changes, including the test runner itself
- CI workflow files
- Anything the mapping does not recognise
A policy you can copy
| Stage | What runs | Blocks merge? |
|---|---|---|
| Pull request, first job | Affected subset | Yes, fast feedback |
| Pull request, second job | Full suite, in parallel or after | Yes, if the team can afford the time |
| Main after merge | Full suite | Alerts, with a revert rule |
| Nightly | Full suite plus slow tests | Alerts |
If the full suite is too slow to block merges, say so and accept the trade-off openly: the subset gates merges, and the full run on main is your net. Track how often the full run fails when the subset passed. That number tells you whether your selection is good enough or leaking.
For flaky failures that appear only in the full run, see self-healing test scripts: how to repair a test without hiding a bug.
Diagram Fast first, complete before you trust it
| Stage | What runs | Blocks merge? |
|---|---|---|
| Pull request, first job | Affected subset | Yes, fast feedback |
| Pull request, second job | Full suite | If you can afford the time |
| Main after merge | Full suite | Alerts, with a revert rule |
| Nightly | Full suite and slow tests | Alerts |
An example of this design in a local agent
Probeflow Desktop is a local AI test agent for your own repository, currently in preview with no public installer. According to its documentation, the app has a command line, built from the project source for now, and probeflow pr selects and runs the tests affected by a pull request and writes a report. It posts to GitHub only if you pass --post.
The tests it writes are ordinary files in your repository, so your CI can run them with probeflow test or your own test command, with no model involved. probeflow test makes no model call and needs no key, its exit code is the result of the suite, and --junit writes a JUnit report. The documentation does not describe how pr chooses tests, so apply the same full-suite rule above to it. Details are in Probeflow Desktop: command line and CI. For how such tests get written, see AI test generation for Playwright.
Sources
- Playwright documentation: Continuous Integration, checked 2026-11-26
- Selective test execution mechanism with Playwright using GitHub Actions (DEV Community), checked 2026-11-26
- Run Only the Playwright Tests Your Change Can Affect (alexop.dev), checked 2026-11-26
- Probeflow Desktop documentation: Command line and CI, checked 2026-11-26
- Probeflow Desktop documentation: Privacy and data, checked 2026-11-26
Frequently asked questions
Can Playwright run only the tests affected by a pull request?
Yes. The --only-changed option runs the test files affected by changes, and in a pull request job you can compare against the base branch. Playwright's documentation calls this a heuristic that might miss tests, so the full suite should still run afterwards.
Why does only-changed miss tests?
It works at the file level, so a change to a shared helper, fixture or configuration may not lead to the tests that depend on it. Selection is only as good as the dependency information it has.
Should the full suite still run on main?
Yes. A subset on the pull request gives fast feedback, but a full run after merge, or in parallel as a required step, is what catches what the subset missed.
Which changes should always trigger every test?
Shared helpers, fixtures, test configuration, dependency upgrades and CI files. When the tool cannot tell what a change affects, running everything is the safe default.