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

Debug specific test filter not applied on Windows #64

Closed
a-type opened this issue Jul 24, 2022 · 10 comments
Closed

Debug specific test filter not applied on Windows #64

a-type opened this issue Jul 24, 2022 · 10 comments
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@a-type
Copy link

a-type commented Jul 24, 2022

Describe the bug
When trying to debug a specific test block, the debug process just runs all tests in the file on Windows with Yarn.

To Reproduce
Steps to reproduce the behavior on the example project:

  1. yarn install
  2. Add a second test block
import { describe, it, expect} from 'vitest';

describe('add', () => {
  it ('1 + 1', () => {
    expect(1 + 1).toBe(2);
  })

  it ('2 + 2', () => {
    expect(2 + 2).toBe(4);
  })
})
  1. Add a breakpoint on line 5, inside the "1 + 1" test
  2. Open the Vitest sidebar and select "Debug test" on "2 + 2"
  3. The breakpoint is hit, indicating "1 + 1" is being run

Expected behavior
When debugging a specific test, I expect to only run that test

Screenshots
If applicable, add screenshots to help explain your problem.
image
Shown above: "2 + 2" is being debugged, but the debugger has broken inside "1 + 1"

The full output for the debug test run:

"C:\Program Files\nodejs\node.exe" .\node_modules\vitest\vitest.mjs test D:/vitest-ext-basic-example/add.test.ts -t ""add 2 + 2"" --api 52918
 DEV  v0.12.10 d:/vitest-ext-basic-example
node_modules/vitest/dist/chunk-vite-node-externalize.464ab3dd.js:10480
      API started at http://localhost:52918
node_modules/vitest/dist/chunk-vite-node-externalize.464ab3dd.js:10480
Could not read source map for file:///d:/vitest-ext-basic-example/@vite/env: ENOENT: no such file or directory, open 'd:\vitest-ext-basic-example\@vite\env.mjs.map'

Environment

(Paste info.txt content generated by the example project)

  • OS: [e.g. macOS] Windows 11
  • VSCode version: 1.69.2
  • Vitest version: 0.12.10
  • Vitest plugin version: v0.2.23 (prerelease)

(filled manually, the setup script does not work on Windows either)

Vitest settings updated
'C:\Users\a-typ\AppData\Local\Programs\Microsoft' is not recognized as an internal or external command,
operable program or batch file.
node:internal/process/promises:246
          triggerUncaughtException(err, true /* fromPromise */);
          ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "undefined".] {
  code: 'ERR_UNHANDLED_REJECTION'
}
@a-type a-type added the p3-minor-bug An edge case that only affects very specific usage (priority) label Jul 24, 2022
@lmexo
Copy link

lmexo commented Aug 1, 2022

This is probably related to the quoting of the test name pattern on windows devices: It is quoted and then later passed to the debug config, which quotes the argument againt, thus, on windows, the comandline looks like: ... tests/add.test.ts -t ""multi word named task"". What windows effectively sees is ... tests/add.test.ts -t multi word named task, so the pattern is actually "multi", whereas "word", "named" and "task" are passed to the filter arguments.

For what I tested, the bug can simply be fixed by removing the following:

if (isWindows)
args.push('-t', `"${testNamePattern}"`)
else

lmexo pushed a commit to lmexo/vitest-vscode-extension that referenced this issue Aug 1, 2022
@zxch3n
Copy link
Member

zxch3n commented Aug 6, 2022

@a-type does it work now on pre-release version?

@a-type
Copy link
Author

a-type commented Aug 6, 2022

Debug run now states No test files found, exiting with code 1. Full output:

"C:\Program Files\nodejs\node.exe" .\node_modules\vitest\vitest.mjs D:/vitest-ext-basic-example/add.test.ts -t "add 2 + 2" --api 60210
 DEV  v0.12.10 d:/vitest-ext-basic-example
node_modules/vitest/dist/chunk-vite-node-externalize.464ab3dd.js:10480
      API started at http://localhost:60210
node_modules/vitest/dist/chunk-vite-node-externalize.464ab3dd.js:10480
filter:  D:/vitest-ext-basic-example/add.test.ts
node_modules/vitest/dist/chunk-vite-node-externalize.464ab3dd.js:10365
include: **/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}
node_modules/vitest/dist/chunk-vite-node-externalize.464ab3dd.js:10367
ignore:  /\/node_modules\//, /\/dist\//
node_modules/vitest/dist/chunk-vite-node-externalize.464ab3dd.js:10369

No test files found, exiting with code 1
node_modules/vitest/dist/chunk-vite-node-externalize.464ab3dd.js:10483
Process exited with code 1

Perhaps because of the forward slashes in the test file path? It's unclear.

I can run node .\node_modules\vitest\vitest.mjs D:/vitest-ext-basic-example/add.test.ts -t "add 2 + 2" --api 60210 in PowerShell and it outputs:

 DEV  v0.12.10 D:/vitest-ext-basic-example
      API started at http://localhost:60210

 ↓ add.test.ts (2) [skipped]

Test Files  1 skipped (1)
     Tests  2 skipped (2)
      Time  1.17s (in thread 0ms, Infinity%)


 PASS  Waiting for file changes...
       press h to show help, press q to quit

So maybe because they're all skipped?

@a-type
Copy link
Author

a-type commented Aug 6, 2022

It might actually be the + symbol in the filter. Running -t "add 2" correctly filters to 2 + 2, but -t add 2 + 2 skips everything. Using a backslash to escape + works: -t "add 2 \+ 2"

@zxch3n
Copy link
Member

zxch3n commented Aug 7, 2022

@a-type thank you for your info. It's weird we need to escape +. Can you run tests correctly on this version?

@a-type
Copy link
Author

a-type commented Aug 7, 2022

My reproduction case still does not work. Attempting to debug an individual test in the example repro does not run anything.

This does not appear to be related to + after all (even though that does seem to be a problem). Apologies for the distraction. For example:

import { describe, it, expect} from 'vitest';

describe('add', () => {
  it ('1 + 1', () => {
    expect(1 + 1).toBe(2);
  })

  it ('2 + 2', () => {
    expect(2 + 2).toBe(4);
  })

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

Running just add foo:
image

Outputs:
image

"C:\Program Files\nodejs\node.exe" .\node_modules\vitest\vitest.mjs D:/vitest-ext-basic-example/add.test.ts -t "add foo" --api 50098
 DEV  v0.12.10 d:/vitest-ext-basic-example
node_modules/vitest/dist/chunk-vite-node-externalize.464ab3dd.js:10480
      API started at http://localhost:50098
node_modules/vitest/dist/chunk-vite-node-externalize.464ab3dd.js:10480
filter:  D:/vitest-ext-basic-example/add.test.ts
node_modules/vitest/dist/chunk-vite-node-externalize.464ab3dd.js:10365
include: **/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}
node_modules/vitest/dist/chunk-vite-node-externalize.464ab3dd.js:10367
ignore:  /\/node_modules\//, /\/dist\//
node_modules/vitest/dist/chunk-vite-node-externalize.464ab3dd.js:10369

No test files found, exiting with code 1
node_modules/vitest/dist/chunk-vite-node-externalize.464ab3dd.js:10483
Process exited with code 1

@jtamyrc
Copy link

jtamyrc commented Aug 8, 2022

Would this issue related to #65 ?

The drive name is a capital case, e.g. C:/ or D:/

@a-type
Copy link
Author

a-type commented Aug 8, 2022

That could be it, yeah.

@IGx89
Copy link
Contributor

IGx89 commented Dec 28, 2022

FYI, the commit made to address this issue (a6019a4) caused quotes to be set properly when debugging (which uses a VS Code API) but turned off quotes when running (which uses spawn), effectively undoing part of #24.

Run commandline:
"C:\Program Files\nodejs\node.exe" .\node_modules\vitest\vitest.mjs /xyz/test/unit/vue-component/vueComponent.spec.ts -t "Vue Component init" --api.port 63875 --api.host 127.0.0.1

Debug commandline:
c:/xyz/node_modules/.bin/vitest.cmd /xyz/test/unit/vue-component/vueComponent.spec.ts -t Vue Component init

@IGx89
Copy link
Contributor

IGx89 commented Dec 28, 2022

I've found a more targeted fix that I'll be PR'ing shortly (#112). As for the issue reported here, I believe it was fully fixed by #94 and think this could be closed now.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

6 participants