vitest-jetbrains-plugin icon indicating copy to clipboard operation
vitest-jetbrains-plugin copied to clipboard

add support for debugging tests

Open donalmurtagh opened this issue 3 years ago • 18 comments

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?

donalmurtagh avatar Jul 01 '22 14:07 donalmurtagh

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.

linux-china avatar Jul 02 '22 19:07 linux-china

hi @linux-china - will there be support for debugging individual tests via your plugin?
per-test debugging & coverage are such killer features

simonmarshall avatar Aug 01 '22 09:08 simonmarshall

@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..

image

Maybe I should group Vitest run, watch and debug together, and you can choose which one to run.

linux-china avatar Aug 01 '22 16:08 linux-china

@donalmurtagh @simonmarshall Debug support implemented with version 0.6.0

image

linux-china avatar Aug 02 '22 00:08 linux-china

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(?)

simonmarshall avatar Aug 03 '22 09:08 simonmarshall

next request: please support coverage as well as debug! :)

simonmarshall avatar Aug 03 '22 09:08 simonmarshall

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

linux-china avatar Aug 03 '22 19:08 linux-china

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 workspaces declared in package.json, and working directory is project's root directory.
  • Vitest Runner will resolve proximate package.json for 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

linux-china avatar Aug 03 '22 19:08 linux-china

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)

simonmarshall avatar Aug 04 '22 17:08 simonmarshall

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 workspaces declared in package.json, and working directory is project's root directory.
  • Vitest Runner will resolve proximate package.json for 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

this now works out-of-the-box in 0.6.1, without using workspaces, thanks!

simonmarshall avatar Aug 05 '22 09:08 simonmarshall

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

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 avatar Aug 05 '22 09:08 simonmarshall

@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"
  }
}

linux-china avatar Aug 05 '22 21:08 linux-china

@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.

simonmarshall avatar Aug 06 '22 08:08 simonmarshall

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.

simonmarshall avatar Aug 23 '22 14:08 simonmarshall

Could you try "@vitest/coverage-c8": "^0.22.1", for a test?

image

linux-china avatar Aug 23 '22 16:08 linux-china

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

simonmarshall avatar Aug 24 '22 09:08 simonmarshall

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.

CamBurris avatar Sep 08 '22 14:09 CamBurris

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

ewoelfel avatar Nov 10 '22 09:11 ewoelfel