Skip to content

Bug: testNamePattern option unnecessarily requires a leading space for an exact match. #6185

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

Closed
6 tasks done
senkenn opened this issue Jul 21, 2024 · 0 comments · Fixed by #6186
Closed
6 tasks done
Labels
p2-edge-case Bug, but has workaround or limited in scope (priority)

Comments

@senkenn
Copy link

senkenn commented Jul 21, 2024

Describe the bug

There is a example test.

it("foo", () => {
  expect(1).toBe(1);
});

We require a leading space for an exact match by testNamePattern.

vitest -t '^ foo$' # '^foo$' skips it.

This is also the same describe name.

On the other hand, Jest can run it by '^foo$'. Is this behavior as expected in Vitest?

Reproduction

  1. Create a JavaScript file like the above, and pnpm i -D vitest
  2. Run pnpm vitest run -t '^foo$' and get the skipped result.
❯ pnpm vitest run -t '^foo$' 
The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.

 RUN  v2.0.3 /home/foo/bar

 ↓ index.test.js (1) [skipped]
   ↓ foo [skipped]

 Test Files  1 skipped (1)
      Tests  1 skipped (1)
   Start at  01:46:52
   Duration  270ms (transform 21ms, setup 0ms, collect 5ms, tests 0ms, environment 0ms, prepare 78ms)
  1. Run pnpm vitest run -t '^ foo$' and get the success result.
❯ pnpm vitest run -t '^ foo$'
The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.

 RUN  v2.0.3 /home/foo/bar

 ✓ index.test.js (1)
   ✓ foo

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  01:50:46
   Duration  266ms (transform 19ms, setup 0ms, collect 5ms, tests 1ms, environment 0ms, prepare 68ms)

System Info

System:
    OS: Linux 6.5 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
    CPU: (16) x64 AMD Ryzen 7 5700U with Radeon Graphics
    Memory: 2.68 GB / 14.94 GB
    Container: Yes
    Shell: 5.8.1 - /usr/bin/zsh
  Binaries:
    Node: 20.14.0 - ~/.nvm/versions/node/v20.14.0/bin/node
    Yarn: 1.22.22 - ~/.local/share/pnpm/yarn
    npm: 10.7.0 - ~/.nvm/versions/node/v20.14.0/bin/npm
    pnpm: 9.5.0 - ~/.local/share/pnpm/pnpm
    bun: 1.0.35 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 126.1.67.123
    Chrome: 126.0.6478.126
  npmPackages:
    vitest: ^2.0.3 => 2.0.3

Used Package Manager

pnpm

Validations

@AriPerkkio AriPerkkio added p2-edge-case Bug, but has workaround or limited in scope (priority) and removed pending triage labels Jul 21, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Aug 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p2-edge-case Bug, but has workaround or limited in scope (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants