vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Debug specific test filter not applied on Windows

Open a-type opened this issue 3 years ago • 8 comments

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 avatar Jul 24 '22 20:07 a-type

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: https://github.com/vitest-dev/vscode/blob/dd70a041b8d955ed821b53684104a1f630044ea0/src/pure/runner.ts#L82-L84

lmexo avatar Aug 01 '22 10:08 lmexo

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

zxch3n avatar Aug 06 '22 04:08 zxch3n

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 avatar Aug 06 '22 16:08 a-type

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"

a-type avatar Aug 06 '22 16:08 a-type

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

zxch3n avatar Aug 07 '22 10:08 zxch3n

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

a-type avatar Aug 07 '22 16:08 a-type

Would this issue related to #65 ?

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

jtamyrc avatar Aug 08 '22 13:08 jtamyrc

That could be it, yeah.

a-type avatar Aug 08 '22 15:08 a-type

FYI, the commit made to address this issue (https://github.com/vitest-dev/vscode/commit/a6019a45d45abb0411f3e6a67eaf5c5f00dead2e) 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 avatar Dec 28 '22 20:12 IGx89

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.

IGx89 avatar Dec 28 '22 23:12 IGx89