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] Doesn't work when Storybook is built with the new --test flag #31

Closed
otaviomad opened this issue Dec 1, 2023 · 3 comments · Fixed by #36
Closed

[Bug] Doesn't work when Storybook is built with the new --test flag #31

otaviomad opened this issue Dec 1, 2023 · 3 comments · Fixed by #36
Labels
bug Something isn't working

Comments

@otaviomad
Copy link

Describe the bug

Storybook 7.6 introduced a new --test flag for building Storybook with less of the fluff that is not needed for testing environments.
When you try to run test-storybook with --coverage on a storybook that was built with --test, I get the following error:

The code in this story is not instrumented, which means the coverage setup is likely not correct.

Steps to reproduce the behavior

  1. Build a Storybook with --test
  2. Run test-storybook on that with --coverage
  3. Rebuild the same Storybook without --test
  4. Test storybook passes

Expected behavior

I believe that the istanbul plugin is not being properly injected when --test is enabled. I don't get the [addon-coverage] Adding istanbul plugin to Vite config message when I use it. The coverage should work when --test is enabled.

@otaviomad otaviomad added the bug Something isn't working label Dec 1, 2023
@otaviomad otaviomad changed the title [Bug] Doesn't work on storybooks built with the new --test flag [Bug] Doesn't work on Storybook is built with the new --test flag Dec 1, 2023
@otaviomad otaviomad changed the title [Bug] Doesn't work on Storybook is built with the new --test flag [Bug] Doesn't work when Storybook is built with the new --test flag Dec 4, 2023
@vicrep
Copy link

vicrep commented Dec 11, 2023

Experiencing the same issue here.

Did a little digging and it seems that the coverage add-on is disabled by default if not overridden? https://github.com/storybookjs/storybook/blob/00124ed94f397d2d6c0a9fa8bbad823cfa1b0ab9/code/lib/core-server/src/presets/common-override-preset.ts#L41

@vicrep
Copy link

vicrep commented Dec 11, 2023

I can confirm that if you are using @storybook/test-runner, that the issue is indeed just that -- that the coverage addon gets removed by default when running a build with the --test flag enabled.

This should probably be fixed, but in the meantime, overriding your build configuration as such does mitigate the issue:

// main.ts
{ ...,
  build: {
    test: {
      disabledAddons: [
        '@storybook/addon-docs',
        '@storybook/addon-essentials/docs',
      ],
    },
  },
}

To maintainers: This does seem like it was accidentally added to the block-list, I'm happy to propose a PR in the SB repo to change that if that is indeed something that shouldn't be set by default -- feels a little odd to me to disable coverage when making a test build of your storybook, which is the prime use-case for coverage.

@jonniebigodes
Copy link
Contributor

@otaviomad, thanks for reporting this, and also @vicrep appreciate your assistance on this 🙏 . So that you're aware, I've pushed a pull request here and will push another into the official documentation to address this until we have a proper fix.

Hope you all have a great day.

Stay safe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants