-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
feat(jest-circus): support literal string match in testNamePattern with "@:" prefix #15667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for jestjs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
babel-jest
babel-plugin-jest-hoist
babel-preset-jest
create-jest
@jest/diff-sequences
expect
@jest/expect-utils
jest
jest-changed-files
jest-circus
jest-cli
jest-config
@jest/console
@jest/core
@jest/create-cache-key-function
jest-diff
jest-docblock
jest-each
@jest/environment
jest-environment-jsdom
@jest/environment-jsdom-abstract
jest-environment-node
@jest/expect
@jest/fake-timers
@jest/get-type
@jest/globals
jest-haste-map
jest-jasmine2
jest-leak-detector
jest-matcher-utils
jest-message-util
jest-mock
@jest/pattern
jest-phabricator
jest-regex-util
jest-repl
@jest/reporters
jest-resolve
jest-resolve-dependencies
jest-runner
jest-runtime
@jest/schemas
jest-snapshot
@jest/snapshot-utils
@jest/source-map
@jest/test-result
@jest/test-sequencer
@jest/transform
@jest/types
jest-util
jest-validate
jest-watcher
jest-worker
pretty-format
commit: |
I'm not interested in supporting magic syntax like this. If we want a direct string match, it should be without any magic, and just the quoted string. |
@cpojer According to the official documentation, --testNamePattern (or -t) is the standard and documented entry point for filtering tests by name:
In practice, users overwhelmingly rely on -t for test filtering — both in local workflows and especially in CI environments. Meanwhile, invoking Jest with a quoted string like jest "some test name" is undocumented, nonstandard, and rarely used or known. As a result, -t is effectively the official and only entry point for name-based filtering. Given this, it’s important that -t itself provides an explicit way to distinguish between regex-based and literal string matching. Introducing a clear and opt-in prefix for literal matching (like @:) serves that need without breaking backward compatibility or existing behavior. This approach acknowledges how people already use Jest, and it keeps filtering behavior discoverable, explicit, and robust within the CLI’s primary filtering interface. I would sincerely appreciate it if you could kindly reconsider this proposal. Thank you. |
Summary
The existing -t / --testNamePattern option in Jest filters test names using regular expressions. This becomes inconvenient when test names include regex-special characters like () or *, which must be manually escaped to run a specific test.
This PR introduces support for literal string matching by allowing a "@:" prefix in testNamePattern. When this prefix is used, the input string is treated as a plain literal rather than a regex. This improves the developer experience by allowing test names to be copied and pasted directly into the CLI without needing to escape special characters.
And, this PR resolves issue #15574
Examples:
Test plan
An end-to-end test suite was added under e2e/literal-pattern to verify the new literal matching behavior. The tests include:
The following commands were run to confirm expected behavior:
All tests passed, and the literal filtering behavior worked as intended.
Regex-based filtering remains unaffected and continues to function normally.