vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Debug test throws Error: No test suite found in file if project is located on D: drive

Open armbzk opened this issue 1 year ago • 15 comments

Describe the bug

Description

  • Running Debug test in vscode vitest extension fails with Error: No test suite found in file D:/gitea/armbzk/vitest-update/tests/dummy.test.mjs
  • Error only occurs with Debug test - Run test succeeds without any error
  • after copying the project to Windows C: drive Debug test works fine
  • npx vitest run in console succeeds (also on D: drive)

Environment

  • vscode 1.95.3
  • OS: Windows_NT x64 10.0.26100 (Windows 11)
  • Nodejs: 20.18.0
  • npm 10.9.1
  • vscode vitest extension v1.8.1
  • vitest 2.1.7
  • MSYS2 GNU bash, version 5.2.37(1)-release (x86_64-pc-msys)

Reproduction

Link to gihub repo: https://github.com/armbzk/vitest-error

tests/dummy.test.mjs:

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

describe('dummy tests', () => {
    it('should succeed', () => {
        expect(true).toBe(true);
    });
});

vitest.config.mts:

import { defineConfig } from 'vitest/config';

export default defineConfig({
    test: {
        environment: 'node',
        include: [
            'tests/*.test.{js,mjs}',
        ],
    },
});

package.json:

{
  "devDependencies": {
    "vitest": "^2.1.7"
  },
  "scripts": {
    "test": "npx vitest run"
  }
}

Output

Output in vscode DEBUG console:

C:\Program Files\nodejs\node.EXE c:\Users\armbzk\.vscode\extensions\vitest.explorer-1.8.1\dist\worker.js
Process exited with code 1

Error message in vitest test explorer:

Error: No test suite found in file D:/gitea/armbzk/vitest-update/tests/dummy.test.mjs
at runFiles (file:///digitea/armbzk/vitest-update/node_modules/@vitest/runner/dist/index.js:1254:11)
at startTests (file:///digitea/armbzk/vitest-update/node_modules/@vitest/runner/dist/index.js:1271:9)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at file:///digitea/armbzk/vitest-update/node_modules/vitest/dist/chunks/runBaseTests.3qpJUEJM.js:126:11
at withEnv (file:///d:/gitea/armbzk/vitest-update/node_modules/vitest/dist/chunks/runBaseTests.3qpJUEJM.js:90:5)
at run (file:///digitea/armbzk/vitest-update/node_modules/vitest/dist/chunks/runBaseTests.3qpJUEJM.js:112:3)
at runBaseTests (file:///d:/gitea/armbzk/vitest-update/node_modules/vitest/dist/chunks/base.BZZh4cSm.js:29:3)
at ForksBaseWorker.executeTests (file:///digitea/armbzk/vitest-update/node_modules/vitest/dist/workers/forks.js:27:7)
at execute (file:///d:/gitea/armbzk/vitest-update/node_modules/vitest/dist/workerjs:127:5)
at onMessage (file:///d:/gitea/armbzk/vitest-update/node_modules/tinypool/dist/entry/processjs:55:20)

Version

v1.8.1

Validations

armbzk avatar Dec 03 '24 10:12 armbzk

What version of Vitest are you using?

sheremet-va avatar Dec 03 '24 10:12 sheremet-va

  • vscode vitest extension v1.8.1
  • vitest 2.1.7

armbzk avatar Dec 03 '24 10:12 armbzk

I'm getting the same issue but it happens only when trying to debug a Vitest unit test in VS Code. Running "npx vitest" works though.

image

using:

Vitest 2.1.8 VS Code Vitest extension v1.8.1 Node: 22.11

Skrypt avatar Dec 03 '24 16:12 Skrypt

I reverted to Vitest 2.0.0 and now it works.

Skrypt avatar Dec 04 '24 18:12 Skrypt

Starts failing at 2.1.4

Skrypt avatar Dec 04 '24 18:12 Skrypt

Same as what Skrypt is experiencing.

Debugging in: Vitest 2.1.3 works Vitest 2.1.4 fails Vitest 3.0.2 fails

VS Code Vitest extension 1.10.2 Node: 18.20.2

Personally I had no need to update to vitest 3 for other reasons, so I simply reverted. But this might become a problem in the future.

Dykam avatar Jan 20 '25 10:01 Dykam

Same issue with vitest 3. one thing i noticed is that if i dont import

import { describe, it } from 'vitest'

it shows the test cases correctly. but if i import it, i get the following error in output

EDIT: NVM the error log I had was unrelated.

EDIT 2: I managed to run the repo and updating vitest version to v3 makes it reproducible.

Main issues comes from getName function. It is now receiving callee as an SequenceExpression, which is not handled in there.

https://github.com/vitest-dev/vscode/blob/a466c6b22ebde48658651bc2471dfd1de7e9f126/src/worker/collect.ts#L79

Addin the following fixes the issue:

if (callee.type === 'SequenceExpression') {
      const memberExpression = callee.expressions.find((e) => e.type === 'MemberExpression')
      if (!memberExpression) {
        return null
      }
      return getName(memberExpression)
    }

But I dont have enough knowledge in ASTs to know how safe this is

tsirlucas avatar Jan 21 '25 18:01 tsirlucas

Correcting myself on previous comment: the problem seems to only happen if youre using vite 6

code sent to AST using vite 6:

const __vite_ssr_import_0__ = await __vite_ssr_import__("/node_modules/vitest/dist/index.js", {"importedNames":["describe","it"]});
(0,__vite_ssr_import_0__.describe)("should included", () => {
  (0,__vite_ssr_import_0__.it)("is included because of workspace plugin setting", () => {
  });
});

//# sourceMappingSource=vite-node
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJtYXBwaW5ncyI6IkFBQUE7R0FFQSxnQ0FBUyxtQkFBbUIsTUFBTTtBQUNoQywrQkFBRyxtREFBbUQsTUFBTTtBQUFBLEVBQUMsQ0FBQztBQUNoRSxDQUFDIiwibmFtZXMiOltdLCJpZ25vcmVMaXN0IjpbXSwic291cmNlcyI6WyJzaG91bGRfaW5jbHVkZWRfdGVzdC50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBkZXNjcmliZSwgaXQgfSBmcm9tICd2aXRlc3QnXG5cbmRlc2NyaWJlKCdzaG91bGQgaW5jbHVkZWQnLCAoKSA9PiB7XG4gIGl0KCdpcyBpbmNsdWRlZCBiZWNhdXNlIG9mIHdvcmtzcGFjZSBwbHVnaW4gc2V0dGluZycsICgpID0+IHt9KVxufSlcbiJdLCJmaWxlIjoiL1VzZXJzL2x1Y2FzY29ycmVpYS9Eb2N1bWVudHMvd29ya3NwYWNlL2NoaWxpcGlwZXIvdnNjb2RlL3NhbXBsZXMvYmFzaWMvc3JjL3Nob3VsZF9pbmNsdWRlZF90ZXN0LnRzIn0=

while in v5:

const __vite_ssr_import_0__ = await __vite_ssr_import__("/node_modules/vitest/dist/index.js", {"importedNames":["describe","it"]});

__vite_ssr_import_0__.describe("should included", () => {
  __vite_ssr_import_0__.it("is included because of workspace plugin setting", () => {
  });
});

//# sourceMappingSource=vite-node
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJtYXBwaW5ncyI6IkFBQUEsQ0FBQTtBQUE2QjtBQUU3QiwrQkFBUyxtQkFBbUIsTUFBTTtBQUNoQywyQkFBRyxtREFBbUQsTUFBTTtBQUFBLEVBQUMsQ0FBQztBQUNoRSxDQUFDIiwibmFtZXMiOltdLCJpZ25vcmVMaXN0IjpbXSwic291cmNlcyI6WyJzaG91bGRfaW5jbHVkZWRfdGVzdC50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBkZXNjcmliZSwgaXQgfSBmcm9tICd2aXRlc3QnXG5cbmRlc2NyaWJlKCdzaG91bGQgaW5jbHVkZWQnLCAoKSA9PiB7XG4gIGl0KCdpcyBpbmNsdWRlZCBiZWNhdXNlIG9mIHdvcmtzcGFjZSBwbHVnaW4gc2V0dGluZycsICgpID0+IHt9KVxufSlcbiJdLCJmaWxlIjoiL1VzZXJzL2x1Y2FzY29ycmVpYS9Eb2N1bWVudHMvd29ya3NwYWNlL2NoaWxpcGlwZXIvdnNjb2RlL3NhbXBsZXMvYmFzaWMvc3JjL3Nob3VsZF9pbmNsdWRlZF90ZXN0LnRzIn0=

Looks like (0,__vite_ssr_import_0__.describe) is parsed as the sequence... I wonder if its safe to assume we will always have a memberExpression as 2nd item. or at least inside the array. Id say its probably safe for us to just do the .find but AST's are new to me

tsirlucas avatar Jan 21 '25 18:01 tsirlucas

I can't debug tests. Facing this same issue. Any workaround on this ?

gkn06 avatar Feb 17 '25 17:02 gkn06

Same problem here. Click the debug button reports this error while normal test execution is fine. Our project is using vite5.4.14

huchenlei avatar Mar 19 '25 17:03 huchenlei

I had the same problem, but after changing the Shell Type setting to terminal, it started working.

Image

auric avatar Mar 24 '25 19:03 auric

I think my problem has the same origin. I reduced it to a very simple Javascript project

https://github.com/snuup/vitest-debug-problem-demo

Debugging from the test explorer is impossible in VSCode or VSCodium. Debugging tests works fine in Jetbrains Rider (quite certainly not using this extension).

Switching to Vite 2.0.0 did not help either.

Changing the Shell Type fixed it, thx @auric .

snuup avatar May 17 '25 11:05 snuup

It seems I have a similar issue. Changing the terminal or downgrading the version didn't help me. I've noticed the following pattern: everything works well when using this approach:

import { test } from 'vitest'

But doesn't work properly when I use the test.extend pattern:

import { myExtendedTest as test } from './helpers.ts'

In this case, when I run tests from the explorer, everything works fine - I see test markers and the suite is detected. But as soon as I save the file, the suite disappears again and I see a "No test suite found" error in the explorer.

dimatakoy avatar Jul 20 '25 19:07 dimatakoy

The normalizeDriveLetter function uses the extension's installation directory drive letter as a reference to normalize all paths, causing incorrect drive conversions when projects are on different drives.

https://github.com/vitest-dev/vscode/blob/4fe71008021338e2873876fa666c4bbb0653b9ab/packages/shared/src/utils.ts#L65-L71

  1. Extension Installation Context
    • VS Code and Vitest extension are installed on C drive
    • __dirname[0] returns C (the extension's installation drive)
    • driveLetter variable is set to C
  2. Project Location
    • User's Vitest project is located on D drive: D:\my-project
    • All project files, configs, and test files are on D drive
  3. Path Conversion During Package Resolution
    • When resolving Vitest packages, the function incorrectly converts the project path.
Input:  'D:\my-project'  
Output: 'C' + '\my-project' = 'C:\my-project'

https://github.com/vitest-dev/vscode/blob/4fe71008021338e2873876fa666c4bbb0653b9ab/packages/extension/src/worker/index.ts#L25 https://github.com/vitest-dev/vscode/blob/4fe71008021338e2873876fa666c4bbb0653b9ab/packages/extension/src/api/resolve.ts#L64 https://github.com/vitest-dev/vscode/blob/4fe71008021338e2873876fa666c4bbb0653b9ab/packages/extension/src/runner.ts#L688

https://github.com/vitest-dev/vscode/blob/4fe71008021338e2873876fa666c4bbb0653b9ab/packages/extension/src/constants.ts#L7-L9

https://nodejs.org/docs/latest/api/modules.html#__dirname

ShortArrow avatar Aug 15 '25 17:08 ShortArrow

I've just experienced this today, for a test on E drive. Switching vitest to terminal while debugging has fixed it, again.

seaders avatar Nov 10 '25 14:11 seaders