vscode
vscode copied to clipboard
No vitest config detected on yarn + pnp + nx projects
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
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.