vscode icon indicating copy to clipboard operation
vscode copied to clipboard

No vitest config detected on yarn + pnp + nx projects

Open saulotoledo opened this issue 11 months ago • 15 comments

Describe the bug

No tests are detected on Yarn + PnP projects. The logs show the following lines

Vitest Workspace [workspace]: Vitest version = undefined
ERR [Extension Host] Cannot run tests: no Vitest config found.

Reproduction

I cannot share the project code I used to verify it, but I believe the investigation below might be enough to highlight the problem.

The function https://github.com/vitest-dev/vscode/blob/main/src/pure/utils.ts#L38 is triggered at https://github.com/vitest-dev/vscode/blob/4283697a5d638105dfabf83ec417f55c5f0669cd/src/config.ts#L81 and only checks for the script at node_modules folder. Yarn PnP projects do not have such folder and, therefore,the resulting command is null. As a consequence, the vitest version is undefined at https://github.com/vitest-dev/vscode/blob/4283697a5d638105dfabf83ec417f55c5f0669cd/src/config.ts#L84

The proposed solutions:

  • Check for yarn.lock and require a script "yarn vitest".
  • Detect for .pnp files. If they exist, consider the command as "yarn vitest".

Additionally, there is an issue with the execution of chunksToLinesAsync(child.stdout) at https://github.com/vitest-dev/vscode/blob/4283697a5d638105dfabf83ec417f55c5f0669cd/src/pure/utils.ts#L113 which empty when the command is correct on the system informed in this bug report. This will result in a failure when loading the version through yarn.

System Info

GNU/Linux, VSCode.

Used Package Manager

yarn

Validations

saulotoledo avatar Mar 10 '24 21:03 saulotoledo