What the agent does
The agent reads the scripts before it reads Jest. In nhannguyen09/mdconvert, a Next.js app that converts Word and PDF files to Markdown, package.json has four test scripts: test runs plain jest, test:unit runs jest --testPathPattern='lib/.*\.test\.ts', test:api runs jest --testPathPattern='app/api/.*\.test\.ts', and test:coverage runs jest --coverage. jest.config.js sets testEnvironment: 'node', a ts-jest transform, a @/ module alias and two testMatch globs under lib/**/__tests__ and app/api/**/__tests__. The devDependencies pin jest at ^30.3.0 with jest-environment-jsdom at the same version and ts-jest at ^29.4.6, and package-lock.json holds jest 30.3.0. Eleven test files exist, nine under lib and two under app/api.
The two filtered scripts fail on the first keystroke. npm run test:unit prints Option "testPathPattern" was replaced by "--testPathPatterns". "--testPathPatterns" is only available as a command-line option. Please update your configuration. and exits 1 before any test file loads. Plain npm test runs all eleven suites and 98 tests pass, which is why the repository's CI workflow, test.yml, is green: it runs npm test -- --ci --coverage on Node 20 and never calls the filtered scripts. The agent fixes the boundary with a scratch project: on jest 30.5.2, --testPathPattern is refused with that message and --testPathPatterns runs the matching suite; on jest 29.7.0, --testPathPattern filters as it always did. Jest 30.0.0 was published 2025-06-10.
The rename is two lines of package.json, --testPathPattern= becoming --testPathPatterns= in both scripts, with the regular expressions unchanged. After it, npm run test:unit reports 9 suites and 81 tests passed with Ran all test suites matching lib/.*\.test\.ts., and npm run test:api reports 2 suites and 17 tests, which add up to the 98 that the plain run reports. The agent searches the rest of the repository for the old flag, in workflows, Makefiles, container files and documentation, and finds it only in those two scripts here.
There is one trap in the other direction, and the agent checks it so the pull request can warn about it. On jest 29.7.0, --testPathPatterns=nomatch is not an error: Jest ignores the unknown option and runs every test, printing Ran all test suites., while --testPathPattern=nomatch on the same version correctly finds no tests and exits 1. So a repository that renames the flag while a branch, a CI image or a shared script still runs Jest 29 gets a filter that silently matches everything. The pull request states which Jest the lock holds and that the rename depends on it.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "Our test scripts fail with: Option \"testPathPattern\" was replaced by \"--testPathPatterns\". Find every place the old flag is passed: package.json scripts, CI workflows, Makefiles, container files, documentation and any script that calls jest. Read the lock file to say which Jest release is installed and confirm in a scratch project which Jest release made the old flag an error and how the old and new flag each behave on Jest 29 and Jest 30, including whether an unknown flag is ignored. Rename the flag everywhere it is passed to the installed Jest, keeping each pattern exactly as it was. Run every renamed script and the plain test script, and show that the filtered counts add up to the full run. Say which scripts CI actually runs and whether CI would have caught this. Open a pull request with the diff, the version findings and the test output of each script.",
"resources": [
{
"url": "https://github.com/your-org/your-app"
}
]
}- Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
- Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
- Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.
What comes back
A pull request that changes two lines of package.json, the test:unit and test:api scripts, and nothing else, because the search found the old flag nowhere else. The description names the installed Jest from the lock, the release that made the flag an error with its date, and the behaviour of both spellings on Jest 29 and 30, quoting the error text and the Ran all test suites. line that shows Jest 29 ignoring the new flag. Below that is the output of all three scripts: 81 tests for the unit pattern, 17 for the API pattern, 98 for the plain run.
The reviewer checks that the two patterns are byte-for-byte what they were, including the escaped dots and the quoting, and that the counts add up, which is the evidence the filters still select the same files. The reviewer also reads the sentence about CI: the workflow runs the plain script, so the broken filters were invisible to it, and the pull request leaves it to the team whether a workflow should run the filtered scripts too.
What the run does not change is the Jest version. The lock already holds Jest 30, and ts-jest 29 works under it in this repository, as the 98 passing tests show; whether to move ts-jest to a matching major is a separate question the pull request names and does not answer.
Run it on every failed test script after a Jest major bump
When the filtered scripts are what CI runs, the error is the first line of a failed job. A step in that workflow that runs only on failure can send the job's log tail to a Rush webhook trigger's URL with the trigger's secret in Authorization: Bearer; the text lands after the saved prompt as the event, so the prompt tells the agent to look for the replaced-option message in it. Send an Idempotency-Key header to the trigger's URL set to the workflow run id, so a re-run of the same job starts nothing new.
When CI runs only the plain script, as this repository's does, nothing fails and the broken scripts wait for the next person to type them. A schedule trigger on an automation in the Project can run every script in package.json whose command starts with jest once a week and open a pull request the week one of them exits with an option error.
The use case this job follows, with its automation and trigger: Fix a bug from an alert.
Why run it on Rush?
The fix is a rename; the knowledge is what each Jest does with each spelling, and that takes two installed versions and four commands. A Rush sandbox installs Jest 29 and Jest 30 side by side in a scratch project, runs the old and new flag under each, and keeps the outputs, so the pull request can say that the new flag is silently ignored on 29 as a fact the reviewer can read rather than a caution they have to take on trust.
Counting is the other proof. Running the two filtered scripts and the plain one in the same sandbox, on the same checkout, and showing 81 and 17 against 98 is what tells the reviewer the patterns still select the files they did, and it costs one more command than the rename itself.
Frequently asked questions
Which Jest release made testPathPattern an error?
Jest 30. On 30.5.2 the old flag is refused with Option "testPathPattern" was replaced by "--testPathPatterns" before any test loads, and on 29.7.0 it filters as before. Jest 30.0.0 was published 2025-06-10, so a ^30 range in devDependencies picks up the change on the next install.
Why is my CI green if the scripts are broken?
Because CI may not run them. In this repository the workflow runs npm test -- --ci --coverage, the plain script, which passes all 98 tests; only test:unit and test:api pass the flag. The pull request says which scripts CI runs so the team can decide whether the filtered ones belong there too.
Can I switch to the new flag while some machines still run Jest 29?
Not safely. On Jest 29.7.0, --testPathPatterns is an unknown option that Jest ignores, so the script runs every test and prints Ran all test suites. instead of filtering. Rename the flag in the same change that moves the lock to Jest 30, and nowhere a Jest 29 still runs it.
Does the pattern itself change?
No. The new flag takes the same regular expressions, and the pull request keeps each one byte for byte, escaped dots and quotes included. The counts after the rename, 81 unit and 17 API tests out of 98, are the check that the same files are selected.
Do I also need to upgrade ts-jest?
Not for this error. The lock holds ts-jest 29.4.6 under Jest 30.3.0 and all 98 tests pass with that pair. Moving ts-jest to a matching major is a separate change, and the pull request names it as one rather than folding it into a two-line rename.