fix(cli): read the watch t pattern as --grep reads one

Merged
TO
4d ago
+109-14

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

  1. compileTitlePattern (packages/e2e/src/cli/title-pattern.ts:11) holds what parsePattern did. 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 in InvalidArgumentError, so the --grep and --grep-invert messages are unchanged.
  2. The t prompt compiles its answer with it (packages/e2e/src/cli/watch.ts:706) where it called new RegExp(value), and invalidPattern (watch.ts:738) validates the trimmed answer with it, the text that gets compiled. The prompt refuses what --grep refuses. /api/users reads users as flags there, as e2e run --grep '/api/users' does, and api/users or \/api\/users selects that title.
  3. 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 .source and 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 as refund would come back as refund. 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 a node target, e2e run --watch driven with expect (press t, type the pattern, enter), on the built CLI of main and of this branch (ANSI codes stripped):
t answermainthis PR
/refund/iRERUN current pattern (title: \/refund\/i), Tests no tests executedRERUN current pattern (title: /refund/i), āœ“ Refund flow
Refundāœ“ Refund flowāœ“ Refund flow
/api/usersruns GET /api/users returns usersrefused in the prompt: must be a regular expression: Invalid flags supplied to RegExp constructor 'users', no rerun
  • e2e run --grep '/refund/i' runs Refund flow on both.
  • tests/unit/cli-watch.test.ts:579 fails on main (validate('/api/users') passes there) and passes here.
  • pnpm record:terminal --tape, same keys on both builds: t, /refund/i, enter, then t again and /api/users, enter.
mainthis PR
mainthis PR

šŸ¤– Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • The e2e run --watch title 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.
  • Documentation
    • Updated the CLI reference to describe the title-pattern format.