Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Addon test includes stories in coverage reports #29613

Closed
Tracked by #29530 ...
yannbf opened this issue Nov 14, 2024 · 3 comments · Fixed by #30059
Closed
Tracked by #29530 ...

[Bug]: Addon test includes stories in coverage reports #29613

yannbf opened this issue Nov 14, 2024 · 3 comments · Fixed by #30059

Comments

@yannbf
Copy link
Member

yannbf commented Nov 14, 2024

Describe the bug

When running vitest with --coverage using Storybook Test plugin, the reports include story files, which is not expected and affects coverage calculations:

Image

The solution is rather simple but has to be done in user land. You can fix it by adding this config to your main vitest (or vite) config:

// vitest.config.ts
import { defineConfig, coverageConfigDefaults } from 'vitest/config'

export default defineConfig({
  // ... rest of your config
  test: {
    coverage: {
      exclude: [
         ...coverageConfigDefaults.exclude, 
         '**/*.stories.*' // or whatever else the users use, e.g. '**/*.story.*' or '**/stories.*'
       ], 
    }
  }
})

This change can't be added in a workspace file because workspaces can't define test.coverage options. Because of that, and the fact that Storybook Test plugin is set up at the workspace level, it makes it impossible for us to set up this configuration automatically as part of the plugin.

Potential solutions for us:

  • Document this limitation and explain how to solve it
  • When executing the postinstall script of addon test, automatically configure the vite configuration file to include coverage exclude options
  • If we don't automatically do it, at least point a link to the docs in the postinstall script

Additionally, we could provide our own export with coverage defaults like so, to make it easier (?) for users:

// vitest.config.ts
import { defineConfig } from 'vitest/config'
import { coverageConfigDefaults } from '@storybook/experimental-addon-test/config'

export default defineConfig({
  // ... rest of your config
  test: {
    coverage: {
      exclude: [
         ...coverageConfigDefaults.exclude, // should include vitest defaults + Storybook defaults
         // Storybook defaults would be '**/*.stories.*', '**/*.story.*', '**/stories.*', '**/story.*'
       ], 
    }
  }
})
@shilman
Copy link
Member

shilman commented Nov 14, 2024

Duplicate to #29597

@shilman
Copy link
Member

shilman commented Dec 4, 2024

@vanessayuenn @JReinhold This should work otherwise the coverage feature is broken out of the box. Bumped this up in priority.

@shilman
Copy link
Member

shilman commented Dec 4, 2024

We should also add storybook-static to the exclude list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants