iFaxity / vite-plugin-istanbul

A Vite plugin to instrument code for nyc/istanbul code coverage. In similar way as the Webpack Loader istanbul-instrumenter-loader. Only intended for use in development.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[bug] coverage does not include code for vue files

DediWang1990 opened this issue · comments

Describe the bug

project use Vue3(^3.3.4) + vite(^5.0.9);

strorybook use VueJsx (https://github.com/vitejs/vite-plugin-vue)

execute ccmmand "test-storybook --coverage", coverage does not include code for vue files.

Reproduction

--

Steps to reproduce

1.storybok main config:

image

2.packages.json:

image

3.coverage result:

image

only some ts file.

System Info

OS: Windows 11
Node.js version: v16.14.2np
NPM version: 8.5.0
Browser (if applicable): chrome
Browser version (if applicable): 121.0.6167.85

Used Package Manager

pnpm

Logs

No response

Validations

Hi @DediWang1990 if "test-storybook --coverage" test with built file (vite build) and not the live server (vite), you need to add forceBuildInstrument: true to the plugin config.

Hi @Nol-go it seems like not working for me even if I add forceBuildInstrument: true I can see warning about sourcemaps during build and also sourcemaps size in the build summary. However, once I start the app there is no windows.coverage nor output of nyc in the folder.

It may be a problem with test-storybook then, did you try oppening the app in your browser and querrying windows.coverage in the console ? If it doesn't exist, then the instrumenting hasn't been built, in which case check the config for the right params. If you do see it, then the problem comes from elsewhere. forcebuildinstrument makes it so that the dist folder containing the compiled project has the instrumentation, if your test command uses the source code and not the compiled one, then the problem is here.
This plugin makes vite create the instrumentation for the test server (vite dev) and for the complied code (vite build) if forcebuildinstrument is set to true.
Note that there are also parameters that require you to set an environment variable for your code to be instrumented.

Also, there's been a recent update (5.0.2 if my memory serves me right) regarding issue #96, that could be linked to your case. (Though it might not if we only take into account your screenshot)

@kubmir The coverage output of nyc is window.__coverage__ not window.coverage. Can you check if it still doesn't output the coverage to the window?

A reproduction repository would be helpful to check for errors and for debugging. Otherwise i am pretty much taking guesses in the dark. As there could be multiple different issues that leads to coverage not being outputted.

There is a planned patch to add more debug logging to check what files are instrumented and which ones are skipped due to exclusion/inclusion patterns.

Closing due to inactivity.