A full Playwright suite may take a long time to run, and a pull request needs an answer sooner than that. The Playwright only-changed option was built for that gap. Simon Knott, who wrote it, described the use as a way to "run changed tests first and fail fast".
--only-changed follows the files your test files load, so its scope is your test code and never the application those tests drive over HTTP or a browser.
What is Playwright only-changed?
It is a command-line option, written --only-changed, that runs only the test files that load a file you changed. Git lists every changed file in the repo, app code included. A changed file selects a test only if a test file imports it, directly or through other files. End-to-end tests reach the app over HTTP, so an app change selects none of them.
The scope is your test code: the spec files and the files they load. That holds whether the app lives in this repo or in another one. Every test in a selected file runs.
The command has 3 forms, and the first looks at work you have not committed yet. The second compares your work with a branch, here main. The third adds --list, which prints the selection without running it.
$ npx playwright test --only-changed
$ npx playwright test --only-changed=main
$ npx playwright test --only-changed=main --list
Every result in this post comes from Playwright 1.65.1, which I ran in a small test project with 14 tests in 9 spec files. Versions before 1.65.0 had 2 bugs, covered further down. The picture below follows one helper file from that project, money.ts, which 2 spec files load through other files.
How does --only-changed pick the tests?
The selection takes 2 steps, and each step has a few rules.
The first command lists new files that git does not track yet, leaving out ignored files. The second lists tracked files that differ between the ref and your working folder. A git ref is a name for a commit, such as a branch name. Playwright runs both commands from the folder that holds playwright.config.ts, so git reports on that repo and no other. Those 2 commands give 4 rules, shown here with an edit to money.ts.
No ref means HEAD, your last commit. Plain --only-changed compares your working folder with that commit.
Edits you have not committed count. The edit selected the same tests before and after I staged it with git add.
New files count. A new spec file that git did not track yet was selected, with or without a ref.
A committed edit needs a ref. After I committed the edit, --only-changed alone selected 0 tests, because HEAD now held it. With --only-changed=main, the same tests were selected again.
Step 2: Playwright keeps the test files that load them
This step uses a dependency graph, which is a map of which files load which other files. Its scope is your test code and nothing else. The graph holds each spec file and the files that load with it, and it leaves out node_modules, the folder where installed packages live.
The application under test has no place in the graph when tests reach it over HTTP or through a browser, because no test file loads the app's files. If the app lives in another repo, step 1 never lists its files. If it lives in this repo, step 1 lists them, but no spec file loads them, so nothing is selected.
Playwright does not build the graph by reading import lines in the source text. It loads every test file, and while each one loads, Playwright records every file that gets loaded with it. Here are 3 lines of the graph from my project.
Each line holds one spec file and the files that loaded with it. checkout.spec.ts loads a page object, checkout-page.ts, which loads money.ts. cart.spec.ts gets there in 3 steps: it loads fixtures.ts, which loads cart-page.ts, which loads money.ts. A fixture file sets up objects that tests use.
The graph has 4 properties that decide what gets selected.
It includes imports of imports.money.ts is on both of the first 2 lines, although no spec file imports it directly.
It is recorded only while test files load. Test bodies run later, in separate worker processes, and nothing is recorded there. A file that a test body loads with import() is missed for that reason.
Selection is by file. Under the selection rule, a changed file selects every test file that has it on its line. A changed test file selects itself.
Selected files run in full. Every test in a selected file runs, and the author of the option confirmed in 2024 that this is intended. When I changed one expectation in checkout.spec.ts, both tests in that file ran.
To see the rules work, I changed one line in money.ts and committed it on a branch.
$ npx playwright test --only-changed=main --list
Listing tests:
cart.spec.ts:3:1 › cart counts two items
cart.spec.ts:7:1 › cart subtotal for two items
checkout.spec.ts:4:1 › checkout total with no coupon
checkout.spec.ts:9:1 › checkout total with SAVE10
Total: 4 tests in 2 files
money.ts is on the lines for cart.spec.ts and checkout.spec.ts, so both files were selected. search.spec.ts was not, because it loads nothing that changed.
How do you use --only-changed?
Use it in 2 places: on your own machine before you commit, and as the first test step of a pull request.
On your own machine
Run it with no ref before you commit. It picks up your unstaged edits, staged edits and new files, and runs only the test files that load them. Add --list first as a dry run. After you commit, pass a ref such as main, because the no-ref form now finds nothing.
On a pull request in CI
Playwright's docs for CI give these steps for GitHub Actions.
- uses: actions/checkout@v6
with:
# Force a non-shallow checkout, so that we can reference $GITHUB_BASE_REF.
# See https://github.com/actions/checkout for more details.
fetch-depth: 0
- uses: actions/setup-node@v6
with:
node-version: lts/*
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run changed Playwright tests
run: npx playwright test --only-changed=origin/$GITHUB_BASE_REF
if: github.event_name == 'pull_request'
- name: Run Playwright tests
run: npx playwright test
In that workflow, 3 things affect how the option runs.
fetch-depth: 0 checks out the full history. Without it you may get a shallow clone, a copy that holds only the latest commit. In a shallow clone without the base branch, Playwright stopped with exit code 1. It said the clone "does not have 'origin/main' available locally".
The ref is origin/$GITHUB_BASE_REF.$GITHUB_BASE_REF holds the name of the base branch, the one the pull request will merge into. origin/ points at the copy of that branch on GitHub. A CI clone usually has origin/main and no local main. In my full clone, --only-changed=main stopped with a git error and --only-changed=origin/main worked.
The full suite runs after the first test step. The if line limits that first step to pull requests, and the full suite step follows it. The docs call the option "a heuristic" that "might miss tests". They tell you to "always run the full test suite after the preliminary test run".
Gary Parker, an independent practitioner who tested the option, gives matching advice: "Keep the full suite on main or the merge queue, and on a schedule". A merge queue is the step that tests a change against the latest main branch just before it merges. The next section shows what the first step cannot see.
What should you watch out for?
The option has 4 behaviors to plan for. After them comes an outside measurement of the first 2.
Changes the graph cannot see
What happens: a change to a file outside the graph selects 0 tests, even when tests depend on that file. The tests in my project call a shop API over HTTP, and I committed a bug in its pricing code, app/pricing.mjs.
$ npx playwright test --only-changed=main --list
Listing tests:
Total: 0 tests in 0 files
The full suite on the same commit failed 4 of the 14 tests.
Why: step 2 set this scope, and Pavel Feldman of the Playwright team put it this way on GitHub in May 2026: "The runner only sees the test files".
In my project, 4 other kinds of change were also outside the graph and selected 0 tests. Playwright loads the config file on its own, outside the step that builds the graph, and it loads global setup the same way. A JSON file read with fs.readFileSync is not loaded as an import. An import() inside a test body runs in a worker, where nothing is recorded.
What to do: read an empty selection as no test file loads a changed file, and never as no test is affected. Run the full suite after it. The table sums up 13 one-file changes from my project, with what was selected and what the full suite found.
An empty selection exits 0 with no message
What happens: when nothing is selected, the run prints no message and exits with code 0. The real run for the pricing bug, npx playwright test --only-changed=main, printed one empty line and nothing else. A filter that matches no test ends differently: it prints an error and exits with code 1.
$ npx playwright test --grep no-test-has-this-title
Error: No tests found
The exit code stays 0 even when another filter is the reason nothing ran. I took a change that selects 4 tests and ran --only-changed with that same --grep added. It ran 0 tests, printed nothing and exited with code 0. Adding --pass-with-no-tests changes nothing, because --only-changed already behaves as if that option were set.
Why: the Playwright team chose this in 2024. Version 1.46, the first with the option, printed "No tests found" and exited 1. Simon Knott asked for that to change and gave his reason: "If folks want to use --only-changed in automation, then exit code 0 is a sane default". Since 1.47, the code skips that error whenever --only-changed is set.
My reading is that exit 0 suits a first-pass job, and it becomes a problem when that job is the only test run on the pull request.
What to do: if the selected step must stand alone, give it a rule for an empty selection. This guard runs everything when the list is empty. Pass it the ref as its first argument.
REF="$1"
LIST="$(npx playwright test --only-changed="$REF" --list)" || { echo "$LIST"; exit 1; }
echo "$LIST" | tail -1
if echo "$LIST" | grep -q '^Total: 0 tests'; then
echo "Nothing selected. Running the full suite."
npx playwright test
else
npx playwright test --only-changed="$REF"
fi
On the pricing bug it printed Total: 0 tests in 0 files, ran all 14 tests and failed 4. The guard covers the empty case only. When one commit held the pricing bug and a harmless spec edit, it ran the 2 selected tests and passed. The full suite failed 4.
The ref is the branch tip, not the merge base
What happens: tests your branch never touched can be selected. I had a branch that edited only one spec file. Meanwhile main gained an edit to a helper that another spec file loads. --only-changed=main listed 3 tests in 2 files.
Why: step 1 runs git diff against the tip of the ref, the newest commit on that branch. It does not use the merge base, the commit where your branch left the main branch. With the merge base as the ref, the same branch listed 2 tests in 1 file. The Playwright team closed a request to use the merge base in 2024.
What to do: bring your branch up to date. When I merged main into the branch first, the extra test went away. Extra tests are the safe kind of error.
Versions before 1.65.0 had 2 bugs
Both bugs made the option miss tests, and version 1.65.0 fixed them. One involved test file names with non-ASCII characters, such as accented letters. The other involved test files that share an import in projects that use ES modules, the newer JavaScript module format.
What Gary Parker measured
Gary Parker published his own test of the option on November 28, 2026. His project is a small shop with 12 browser tests. He made 8 changes, one commit each: 3 to test code, 3 to app code, 1 to the config file and 1 README-only edit. He planted a bug in 7 of them and ran each one with --only-changed and with the full suite.
His headline: "--only-changed caught 13 of the 27 tests the bugs broke". The 27 is the total of failing tests across his 8 changes, counted on the full suite. By his count, the 3 changes to test code selected the right files and caught every failure. The other 5 selected nothing. In those 5, the option "ran 0 tests, printed nothing and exited 0". He adds that "4 of those 5 had a bug that failed between 1 and 9 tests on the full suite".
I applied his 8 edits to his public repository and listed the selection with Playwright 1.65.1. The counts matched his, but I did not run his browser tests, so the failure counts are his alone.
Treat his numbers and mine with care, because each comes from one small project with planted bugs on one machine. He also maintains a competing tool, playwright-affected, which I did not test.
How do you map app changes to tests?
In the test repo, --only-changed still covers changes to the test code. A change in an app repo needs a link that your team writes down. This section builds one for an app in several repos, with the Playwright tests in their own repo and GitHub Actions as the CI. I ran the lookup script and the git commands on my machine. The request and the workflow are untested examples, because I could not run GitHub Actions. Repo names, paths and tags are examples.
Tag the tests by area
Playwright's docs on tags put a tag in a details object on a test or on a group. They note that "tags must start with @ symbol". This is one test from my tagged copy of the project.
test('global setup set the shop region', { tag: '@smoke' }, async () => {
expect(process.env.SHOP_REGION).toBe('GB');
});
--grep takes a regular expression, so tags joined with | select the tests that have any of them.
Write one map in the test repo
The map is one JSON file, keyed by app repo. Each repo has 3 lists, and one more list applies to every repo.
fullRunTriggers are paths where any change runs every test. In an app repo, shared code and the lockfile are candidates. Parker advises putting "the config, the lockfile, shared page objects and the map itself" in that list. In the test repo's own pipeline, a change to the config or the map should run everything too.
ignore lists paths that need no tests, such as docs.
mappings tie a path prefix to the tags it needs.
alwaysRunTags adds a few smoke tests to every selection.
The tool Parker maintains has its own format for such rules. This map is plain JSON, so it depends on nothing.
Send each app change to the test repo
Each app repo's CI lists the paths its branch changed, with git.
In a scratch repo on my machine, this command printed docs/api.md,src/pricing/tax.js. Without the merge base, the diff also listed a file that only main had changed. The merge base needs history: in a depth-1 clone, git merge-base found nothing, so use fetch-depth: 0 here too.
GitHub's docs describe a request that can carry the list, Create a repository dispatch event. Its body holds an event_type and a client_payload.
The repo name and the token in that request are placeholders, and the token must be able to write to the test repo. For a fine-grained token, the docs ask for "Contents" repository permissions (write). The payload is small by design: 10 top-level properties and under 64 KB. I built this body and parsed it as JSON, but I did not send the request.
Start a workflow in the test repo
In the test repo, a workflow starts on that event type. It reads the payload from github.event.client_payload, the way the docs sample does.
The docs add 2 conditions: the workflow file must exist on the default branch, and the run uses the last commit on that branch. The run belongs to the test repo, so reporting the result back to the app pull request is a further step. It also assumes that the changed app is running somewhere the tests can reach.
Look the change up in the map
The last step of that workflow runs run-selected.sh, a short wrapper. The wrapper first calls select-tests.mjs, a lookup script with no dependencies. It reads the map and the changed paths, and it prints a --grep pattern or the word FULL.
// Prints a --grep pattern for the changed paths of one app repo, or FULL.
// Use: node select-tests.mjs <map.json> <repo> <comma-separated changed paths>
import { readFileSync } from 'node:fs';
const [mapFile, repo, pathList = ''] = process.argv.slice(2);
const map = JSON.parse(readFileSync(mapFile, 'utf8'));
const rules = map.repos[repo];
const paths = pathList.split(/[,\n]/).map(p => p.trim()).filter(Boolean);
const matches = (path, prefixes = []) => prefixes.some(prefix => path.startsWith(prefix));
const full = reason => {
console.error(`full suite: ${reason}`);
console.log('FULL');
process.exit(0);
};
if (!rules) full(`no rules for repo "${repo}"`);
if (paths.length === 0) full('no changed paths were sent');
const tags = new Set(map.alwaysRunTags);
for (const path of paths) {
if (matches(path, rules.fullRunTriggers)) full(`${path} is a full-run trigger`);
if (matches(path, rules.ignore)) continue;
const hits = rules.mappings.filter(mapping => matches(path, mapping.paths));
if (hits.length === 0) full(`${path} is not mapped`);
for (const hit of hits) hit.tags.forEach(tag => tags.add(tag));
}
if (tags.size === 0) full('nothing selected and no always-run tags');
console.log([...tags].join('|'));
For each path the rules run in order. A full-run trigger stops with FULL, and an ignored path is skipped. A mapped path adds its tags, and an unmapped path stops with FULL. An unknown repo or an empty list also gives FULL. These are 3 of the 10 cases I ran.
$ node select-tests.mjs map.json orders-service src/pricing/tax.js
@smoke|@checkout|@cart
$ node select-tests.mjs map.json orders-service src/new-feature/index.js
full suite: src/new-feature/index.js is not mapped
FULL
$ node select-tests.mjs map.json orders-service docs/api.md
@smoke
The wrapper turns that answer into a test run, and I ran it on my tagged copy of the project.
PATTERN=$(node "$(dirname "$0")/select-tests.mjs" "$1" "$2" "$3") || exit 1
echo "selection: $PATTERN"
if [ "$PATTERN" = "FULL" ]; then
npx playwright test
else
npx playwright test --grep "$PATTERN"
fi
The pricing path ran 5 of the 14 tests and passed. The lockfile path ran all 14. Run on its own, a pattern that matches no tag fails with "No tests found". Through the script, every pattern includes @smoke, so a mapped tag that no test carries runs only the smoke tests and can pass. Check that every tag in the map has tests.
Shadow first, then gate
Parker's advice is to "run it in shadow mode next to the full suite" before you make selection blocking. In shadow mode the map selects tests on every pull request, but the check turns green or red on the full suite's result. You count the failures the selection would have missed, and each miss shows you a rule to add. After that, the full suite stays on main or the merge queue, as before. Parker also names the limit of any map: "The map is only as good as the person who writes it".
If the app and the tests share one repo
In that layout, skip the request and the second workflow, and run the same git command in that repo's CI job. Pass the paths to the script under one repo key. --only-changed can still run first for the test code.
How can you check your own pipeline?
One check shows what your own pipeline does with an empty selection.
On a new branch, change one application file that no test imports. A comment is enough.
Run npx playwright test --only-changed=origin/main --list, with your base branch in place of main. The expected result is Total: 0 tests in 0 files. If tests are listed, there are 3 possible causes. A test file may load that file. Another file in your working folder may have changed. Or your base branch has moved, so bring the branch up to date and run it again.
Open a pull request. In the job log, read how many tests ran and the status of the check.
For a safe pipeline, the expected result in step 3 is a test count above 0 or a failed job. If the check is green and the count is 0, any change outside the test code can merge untested. I ran steps 1 and 2 on my test project.
With the app in other repos, the check has one step, and I have not run it. Change one file in an app repo, open a pull request there, and look in the test repo for a run that the change started. For a safe setup, the expected result is a run with a test count above 0. If no run starts, app changes reach main without an end-to-end test.
Where Nopmark fits
The ISTQB Foundation syllabus has a name for what this option does. Section 2.2.3 says "Impact analysis shows which parts of the software could be affected", and it advises doing that first "to recognize the extent of the regression testing". --only-changed is impact analysis by one rule: which test files load a changed file. The syllabus also says the harm from a change can reach "other components in the same system". If your team is deciding what a pull request must run before it merges, you can contact Nopmark about team training.
Questions about Playwright only-changed
Does it work when the app lives in other repos?
No. Git runs in the test repo, so it sees no change there, and the app's files are never in the graph. Even an app installed as a package sits in node_modules, which the graph leaves out. For that layout you need a map from app changes to tests, as in the mapping section.
A Selenium to Playwright migration is the testing theme of 2026. TestGuild's survey of 40,000+ testers puts the shift at the top of the trend list, and Reddit's testing communities…