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]: Test coverage report broken for @storybook/nextjs #26344

Closed
rotous opened this issue Mar 6, 2024 · 4 comments
Closed

[Bug]: Test coverage report broken for @storybook/nextjs #26344

rotous opened this issue Mar 6, 2024 · 4 comments

Comments

@rotous
Copy link

rotous commented Mar 6, 2024

Describe the bug

  • Create a standard NextJS project with the following command: npx create-next-app@latest
  • Add Storybook with the following command: npx sb init --builder webpack5
  • Add @storybook/nextjs with the following command: npm install --save-dev @storybook/nextjs@next
  • Update the config in .storybook/main.js with the following line: framework: '@storybook/nextjs', (as documented on https://storybook.js.org/docs/8.0/get-started/nextjs)
  • Add the test-runner with: npm install @storybook/test-runner --save-dev
  • Add "test-storybook": "test-storybook" to the scripts in package.json
  • Add the coverage addon with npm install @storybook/addon-coverage --save-dev
  • Start Storybook with npm run storybook
  • Create the coverage report with npm run test-storybook -- --coverage
  • Output the report to the console with npx nyc report -t coverage/storybook/

Result:

PASS browser: chromium src/stories/Header.stories.js
PASS browser: chromium src/stories/Button.stories.js
PASS browser: chromium src/stories/Page.stories.js

Test Suites: 3 passed, 3 total
Tests: 8 passed, 8 total
Snapshots: 0 total
Time: 1.711 s, estimated 2 s
Ran all test suites.
Coverage file (2 bytes) written to .nyc_output/coverage.json

File % Stmts % Branch % Funcs % Lines Uncovered Line #s
All files 0 0 0 0

To Reproduce

No response

System

Storybook Environment Info:

  System:
    OS: Linux 5.15 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i7-13700H
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 20.11.0 - ~/.nvm/versions/node/v20.11.0/bin/node
    npm: 10.5.0 - ~/.nvm/versions/node/v20.11.0/bin/npm <----- active
  npmPackages:
    @storybook/addon-coverage: ^1.0.1 => 1.0.1
    @storybook/addon-essentials: ^7.6.17 => 7.6.17
    @storybook/addon-interactions: ^7.6.17 => 7.6.17
    @storybook/addon-links: ^7.6.17 => 7.6.17
    @storybook/addon-onboarding: ^1.0.11 => 1.0.11
    @storybook/blocks: ^7.6.17 => 7.6.17
    @storybook/nextjs: ^7.6.17 => 7.6.17
    @storybook/react: ^7.6.17 => 7.6.17
    @storybook/test: ^7.6.17 => 7.6.17
    @storybook/test-runner: ^0.16.0 => 0.16.0
    eslint-plugin-storybook: ^0.8.0 => 0.8.0
    storybook: ^7.6.17 => 7.6.17

Additional context

The issue seems to be introduced with @storybook/nextjs@7.6.0-alpha.5. The coverage reporting works fine up until @storybook/nextjs@7.6.0-alpha.4:

Storybook Environment Info:

  System:
    OS: Linux 5.15 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i7-13700H
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 20.11.0 - ~/.nvm/versions/node/v20.11.0/bin/node
    npm: 10.5.0 - ~/.nvm/versions/node/v20.11.0/bin/npm <----- active
  npmPackages:
    @storybook/addon-coverage: ^1.0.1 => 1.0.1
    @storybook/addon-essentials: ^7.6.17 => 7.6.17
    @storybook/addon-interactions: ^7.6.17 => 7.6.17
    @storybook/addon-links: ^7.6.17 => 7.6.17
    @storybook/addon-onboarding: ^1.0.11 => 1.0.11
    @storybook/blocks: ^7.6.17 => 7.6.17
    @storybook/nextjs: ^7.6.0-alpha.4 => 7.6.0-alpha.4
    @storybook/react: ^7.6.17 => 7.6.17
    @storybook/test: ^7.6.17 => 7.6.17
    @storybook/test-runner: ^0.16.0 => 0.16.0
    eslint-plugin-storybook: ^0.8.0 => 0.8.0
    storybook: ^7.6.17 => 7.6.17

Output of $ npx nyc report -t coverage/storybook/:

File % Stmts % Branch % Funcs % Lines Uncovered Line #s
All files 93.93 77.77 66.66 87.5
Button.jsx 100 71.42 100 100 19
Header.jsx 100 100 100 100
Page.jsx 81.81 100 50 66.66 14-15
@yamish123
Copy link

I have same issue too.

@valentinpalkovic
Copy link
Contributor

valentinpalkovic commented Apr 6, 2024

Hi @rotous and @yamish123

This got very likely fixed in Storybook 8.0.6. Could you please try it out?

@yamish123
Copy link

@valentinpalkovic
Thanks! This issue is solved for me at Storybook 8.0.6.

@rotous
Copy link
Author

rotous commented Apr 23, 2024

Finally had time to update. The issue is fixed for me too with Storybook v8.0.8. Thanks!

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

No branches or pull requests

4 participants