vitest-jetbrains-plugin
vitest-jetbrains-plugin copied to clipboard
add support for debugging tests
In IntelliJ (or Webstorm), it is possible to debug Jest tests by choosing the debug option from the dropdown menu. This allows you to set breakpoints, step through the code, etc.
Would it be possible to support debugging for Vitest tests?
Yes, I know this problem, and debugging needs more works :) Now you can debug test by https://github.com/linux-china/vitest-jetbrains-plugin#how-to-debug-vitest-tests
I will take a look and use run configuration to run Vitest test, then debug will be available.
hi @linux-china - will there be support for debugging individual tests via your plugin?
per-test debugging & coverage are such killer features
@simonmarshall I will take a look. Now I use RunAnything to launch Vitest tests instead of Run Configuration. Maybe I should choose Run Configuration to launch Vitests, and then you can debug Vitest tests from Run Configuration.
It's not hard to add debug support in WebStorm, just create a Vitest base test run configuration, and copy this configuration to run other tests..

Maybe I should group Vitest run, watch and debug together, and you can choose which one to run.
@donalmurtagh @simonmarshall Debug support implemented with version 0.6.0

awesome @linux-china - thanks! it assumes our working directory is the project root, so we have to manually adjust each run config to add the appropriate sub-folder, but i guess there's no way around that(?)
next request: please support coverage as well as debug! :)
next request: please support coverage as well as debug! :)
Please add c8 dependency in package.json and reopen the project. If c8 found in package.json, and Vitest Runner will add --coverage automatically. Fixed in version 0.6.1
awesome @linux-china - thanks! it assumes our working directory is the project root, so we have to manually adjust each run config to add the appropriate sub-folder, but i guess there's no way around that(?)
How Vitest Runner plugin resolves working directory?
- If
workspacesdeclared inpackage.json, and working directory is project's root directory. - Vitest Runner will resolve proximate
package.jsonfor Vitest tested file, and working directory may be project's root directory or subdirectory of subproject.
Attention: for mono repository with subprojects independent, working directory will be subproject's directory,
and Vitest Runner will use vite.config.js inside subproject.
Fixed in version 0.6.1
thanks @linux-china - i'll try both issues when 0.6.1 comes out (we do already have a c8 dev dep so assumed coverage wasn't supported)
awesome @linux-china - thanks! it assumes our working directory is the project root, so we have to manually adjust each run config to add the appropriate sub-folder, but i guess there's no way around that(?)
How Vitest Runner plugin resolves working directory?
- If
workspacesdeclared inpackage.json, and working directory is project's root directory.- Vitest Runner will resolve proximate
package.jsonfor Vitest tested file, and working directory may be project's root directory or subdirectory of subproject.Attention: for mono repository with subprojects independent, working directory will be subproject's directory, and Vitest Runner will use
vite.config.jsinside subproject.Fixed in version 0.6.1
this now works out-of-the-box in 0.6.1, without using workspaces, thanks!
next request: please support coverage as well as debug! :)
Please add
c8dependency in package.json and reopen the project. If c8 found in package.json, and Vitest Runner will add--coverageautomatically. Fixed in version 0.6.1
we do have a c8 7.12.0 dev dep in our subproject's package.json, but vitest runner doesn't seem to add --coverage to the normal runner, if that's what you mean:
npm.cmd exec -- vitest run -t "fubar" src/foo/bar.spec.ts
RUN v0.20.2 C:/Users/Snafu/Repos/repo/subproject
i was assuming it would be available as a Coverage entry in the dropdown, like Watch & Debug, but i don't see it there either. i usually wouldn't want to run with coverage.
@simonmarshall c8 should be declared in root package.json. Vitest runner will not detect every package.json in sub projects.
{
"devDependencies": {
"c8": "^7.12.0"
}
}
@simonmarshall c8 should be declared in root package.json. Vitest runner will not detect every package.json in sub projects.
Ok, I think I tried that too, without any luck. I'm traveling for a couple of weeks, but will try again when I can.
hi @linux-china - i can confirm with 0.6.3 that even if c8 is in devDependencies in the root package.json that there is no Coverage entry in the dropdown menu, alongside Watch & Debug.
Could you try "@vitest/coverage-c8": "^0.22.1", for a test?

where should i see this happen?
if it's a normal test run, via green triangle, i can't test that due to the windows path issues if it's under the dropdown menu, alongside Watch & Debug, then no there's no Coverage entry
i would expect it under the dropdown menu, but maybe my expectations are wrong
I see the --converage flag being added, but only when I use the Debug option. I have noticed that the coverage appears to be broken though? There is output for the coverage report but it doesn't have any data. If I take the command that is being executed and run it manually in the terminal I do see proper coverage.
awesome @linux-china - thanks! it assumes our working directory is the project root, so we have to manually adjust each run config to add the appropriate sub-folder, but i guess there's no way around that(?)
the pr https://github.com/linux-china/vitest-jetbrains-plugin/pull/35 should fix this behaviour