test-runner icon indicating copy to clipboard operation
test-runner copied to clipboard

Coverage report from all files

Open mlewando-cp opened this issue 2 years ago • 5 comments

It looks like to coverage generated with this plugin comes only from files that were tested. Is there a way to have a coverage report from the whole project (include files that were not touched by storybook)?

I'm using https://storybook.js.org/addons/@storybook/test-runner to run tests and collect coverage

mlewando-cp avatar Oct 27 '22 09:10 mlewando-cp

I believe (untested) that you can configure the Istanbul to collect coverage from all files with all flag, which you can set through the addon options.istanbul.

module.exports = {
  addons: [
    { 
      name: '@storybook/addon-coverage',
      options: {
        istanbul: {
          all: true
        }
      }  
    }
  ],
};

See the documentation of istanbul/nyc for Selecting files for coverage.

The options passed to the addon as options.istanbul are all appended to the istanbul plugin, so you are be able to configure istanbul through the options, only the options are enhanced with the addon specific configs, that might conflict with yours so if the all will not work, try to inspect the source code a little bit more.

https://github.com/storybookjs/addon-coverage/blob/bfab9eacfaee79ba73dae3f6f878c814f3593126/src/preset.ts#L38

czabaj avatar Nov 08 '22 16:11 czabaj

I believe (untested) that you can configure the Istanbul to collect coverage from all files with all flag

I might be wrong, but I think this won't work for the cases where files are not imported (directly or otherwise) by any story. It would be nice to be able to flag such files as having 0 coverage.

nathanpower avatar Nov 18 '22 13:11 nathanpower

all flag did not work and as @nathanpower said, I was not able to "trick" the coverage to count files that are not imported into any story. And what I need is exactly to report those files at 0 coverage

mlewando-cp avatar Nov 25 '22 05:11 mlewando-cp

I don't think this issue belongs to @storybook/addon-coverage, but instead to https://github.com/storybookjs/test-runner. This plugin only instruments the code. It would be the task of the test-runner, though, to deliver a coverage report for all files. WDYT @yannbf

valentinpalkovic avatar Nov 10 '23 08:11 valentinpalkovic

I don't think this issue belongs to @storybook/addon-coverage, but instead to storybookjs/test-runner. This plugin only instruments the code. It would be the task of the test-runner, though, to deliver a coverage report for all files. WDYT @yannbf

Great point. Moved!

yannbf avatar Dec 01 '23 11:12 yannbf