fix(cli): read the watch t pattern as --grep reads one
Merged
TO
4d ago+109+109+012345678901234567890123456789-14-14-01234567890123456789
What
The t prompt of e2e run --watch reads a title pattern the way --grep does, so /refund/i selects "Refund flow". The rerun banner and the next t prompt show the pattern with its flags.
Why
docs/reference/cli.mdx says t "prompts for a title pattern, as --grep", and --grep takes /pattern/flags. The prompt compiled the text as written, so /refund/i matched only a title containing the literal /refund/i. The rerun selected nothing and passed empty, with no error. This change sends the prompt through the same parser as --grep.
How it works
compileTitlePattern(packages/e2e/src/cli/title-pattern.ts:11) holds whatparsePatterndid. It reads a bare pattern or/pattern/flags, and throws with the reason on an empty or invalid one.parsePattern(packages/e2e/src/cli/index.ts:80) wraps it inInvalidArgumentError, so the--grepand--grep-invertmessages are unchanged.- The
tprompt compiles its answer with it (packages/e2e/src/cli/watch.ts:706) where it callednew RegExp(value), andinvalidPattern(watch.ts:738) validates the trimmed answer with it, the text that gets compiled. The prompt refuses what--greprefuses./api/usersreadsusersas flags there, ase2e run --grep '/api/users'does, andapi/usersor\/api\/usersselects that title. titlePatternText(title-pattern.ts:29) writes a pattern back for the banner (watch.ts:427) and the prompt's initial value (watch.ts:701), which used.sourceand dropped the flags. It writes the bare source when the pattern has no flags and no space at either end, else/source/flags: the prompt reads its answer trimmed, so/refund /reopened asrefundwould come back asrefund. A source never starts with an unescaped/, so the bare form never reads back as the slashed one.
Issue
Fixes #2443
Verified
Ran it locally: yes
- A scratch project with three tests (
GET /api/users returns users,Refund flow,checkout pays) and anodetarget,e2e run --watchdriven withexpect(presst, type the pattern, enter), on the built CLI of main and of this branch (ANSI codes stripped):
t answer | main | this PR |
|---|---|---|
/refund/i | RERUN current pattern (title: \/refund\/i), Tests no tests executed | RERUN current pattern (title: /refund/i), ā Refund flow |
Refund | ā Refund flow | ā Refund flow |
/api/users | runs GET /api/users returns users | refused in the prompt: must be a regular expression: Invalid flags supplied to RegExp constructor 'users', no rerun |
e2e run --grep '/refund/i'runsRefund flowon both.tests/unit/cli-watch.test.ts:579fails on main (validate('/api/users')passes there) and passes here.pnpm record:terminal --tape, same keys on both builds:t,/refund/i, enter, thentagain and/api/users, enter.
| main | this PR |
|---|---|
![]() | ![]() |
š¤ Generated with Claude Code
Summary by CodeRabbit
- New Features
- The
e2e run --watchtitle prompt accepts patterns in the same format as--grep, including regular-expression flags such as/refund/i. - Invalid patterns are rejected. Accepted patterns, including their flags, appear in the rerun banner and next prompt.
- The
- Documentation
- Updated the CLI reference to describe the title-pattern format.

