Skip to content
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

Running individual test on windows uses a caret (^) as escape character in the testNamePattern #1175

Closed
necjosh opened this issue Sep 4, 2024 · 4 comments · Fixed by #1179
Labels

Comments

@necjosh
Copy link

necjosh commented Sep 4, 2024

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.

describe("foo >", () => {
    it("bar", () => {
        expect(1).toBe(1);
    });
});
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:

describe("foo ` ~ ! @ # $ % ^ & * ( ) { } [ ] / = ? + _ - , . < > ' \"", () => {
    it("bar", () => {
        expect(1).toBe(1);
    });
});
Test Suites: 1 skipped, 0 of 1 total
Tests:       1 skipped, 1 total
Snapshots:   0 total
Time:        1.712 s
Ran all test suites matching [omitted]\\src\\App\.test\.js/i with tests matching "foo ` ~ ^! @ # \$ % \^^ ^& \* \( \) \{ \} \[ \] / = \? \+ _ - , \. ^< ^> ' " bar$".

! ^ & < > are affected.

To Reproduce
Sample repo

Steps to reproduce the behavior:

  1. Run the single test in the UI
  2. See error

Expected behavior
Backslashes are used to escape special characters in the testNamePattern.

Environment (please complete the following information):

  • vscode-jest version: v6.2.5
  • node -v: 21.6.1, also tested on LTS 20.17.0
  • npm -v or yarn --version: npm 10.2.4
  • jest or react-scripts (if you haven’t ejected) version: react-scripts 5.0.1 (also tested on company's repo using Jest v29.7.0, no react-scripts)
  • your vscode-jest settings:
    • jest.jestCommandLine? N/A
    • jest.runMode? on-demand
    • jest.outputConfig? none
    • anything else that you think might be relevant? The error was reproduced by all my colleagues, with varying setups, although all running Windows 11.
  • Operating system: Windows 11 Business version 23H2

Prerequisite

  • are you able to run jest from the command line? yes
  • where do you run jest CLI from? root directory of the project
  • how do you run your tests from the command line? npm run test, npx jest
@necjosh
Copy link
Author

necjosh commented Sep 5, 2024

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.

@necjosh
Copy link
Author

necjosh commented Sep 5, 2024

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.

@connectdotz
Copy link
Collaborator

yes, this looks like a bug... thanks for raising the issue, I will take a look.

@connectdotz
Copy link
Collaborator

@necjosh, I think I have a fix. Do you mind confirming if the new build fixes your issue:
vscode-jest-6.3.0.vsix.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants