You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Instead of a backslash, a caret is used to escape special characters in the testNamePattern when running an individual test through the UI.
This causes the test to be skipped.
What I also find curious is that the testNamePattern is included in the command at all. I'm running the entire test file, I don't understand why it's including it since the testPathPattern already narrows it down to the file exclusively.
Test Suites: 1 skipped, 0 of 1 total
Tests: 1 skipped, 1 total
Snapshots: 0 total
Time: 1.262 s
Ran all test suites matching [omitted]jest-repro\\src\\App\.test\.js/i with tests matching "foo ^> bar$".
Spawn command: [Extension Host] spawning process with command=npm test -- --testLocationInResults --json --useStderr --outputFile [omitted] --testNamePattern "foo ^> bar$" --no-coverage --reporters default --reporters "[omitted]" --colors --watchAll=false --testPathPattern "[omitted]\\src\\App\.test\.js"
I added more special characters to see which ones are affected:
I had no idea that ^ is used as an escape character in CMD....
Anyway, it seems that there is no need to use an escape character in the testNamePattern, I suppose because it's in quotes?
CMD does not interpret ^ as an escape character in this portion of the command, so it's passed on as an actual part of the regexp.
I confirmed this by running a few commands in CMD.
#command:Echo THIS & THAT#output:THIS'THAT'is not recognized as an internal or external command,operable program or batch file.#command:Echo THIS ^& THAT#output:THIS & THAT#command:Echo "THIS & THAT"#output:"THIS & THAT"#command:Echo "THIS ^& THAT"#output:"THIS ^& THAT"
As you can see in the last example, the caret does not act as an escape character in this case.
Describe the bug
Instead of a backslash, a caret is used to escape special characters in the
testNamePattern
when running an individual test through the UI.This causes the test to be skipped.
What I also find curious is that the
testNamePattern
is included in the command at all. I'm running the entire test file, I don't understand why it's including it since thetestPathPattern
already narrows it down to the file exclusively.Spawn command:
[Extension Host] spawning process with command=npm test -- --testLocationInResults --json --useStderr --outputFile [omitted] --testNamePattern "foo ^> bar$" --no-coverage --reporters default --reporters "[omitted]" --colors --watchAll=false --testPathPattern "[omitted]\\src\\App\.test\.js"
I added more special characters to see which ones are affected:
! ^ & < >
are affected.To Reproduce
Sample repo
Steps to reproduce the behavior:
Expected behavior
Backslashes are used to escape special characters in the testNamePattern.
Environment (please complete the following information):
node -v
: 21.6.1, also tested on LTS 20.17.0npm -v
oryarn --version
: npm 10.2.4Prerequisite
npm run test
,npx jest
The text was updated successfully, but these errors were encountered: