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] No coverage for file reported if JSX is used #34

Open
jMalojlo opened this issue Dec 4, 2023 · 7 comments
Open

[Bug] No coverage for file reported if JSX is used #34

jMalojlo opened this issue Dec 4, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@jMalojlo
Copy link

jMalojlo commented Dec 4, 2023

Describe the bug

Coverage is not reported for files where JSX is used.

I've set up a minimal repository that recreates the issue with the same config - https://github.com/jMalojlo/sb-repro.
It's a basic button component with a story containing a play function to 'test' a click handler.
The component itself contains some JSX and imports some jsx and non-jsx module. What we see in the coverage report is that only the files without JSX are properly counted.
We're running an ejected CRA and I assume it's a Babel config issue, but can't figure this out myself.

Steps to reproduce the behavior

  1. Clone https://github.com/jMalojlo/sb-repro
  2. npm install && npx playwright install chrome
  3. npm run storybook
  4. npm run storybook-test runs tests with --coverage
  5. npm run generate-storybook-coverage nyc report with lcov
  6. open ./coverage/storybook/lcov-report/index.html to inspect the coverage HTML file
  7. Screenshot 2023-12-04 at 18 33 02

Environment

  • Node.js version: 20.9.0
  • NPM version: 10.1.0
@jMalojlo jMalojlo added the bug Something isn't working label Dec 4, 2023
@jMalojlo
Copy link
Author

For anyone stumbling upon this: Pin @storybook/react-webpack5 to 7.5.3. Anything higher breaks the report for JSX.
You can safely run all the other Storybook deps at latest (currently 7.6.4) though.

@thehig
Copy link

thehig commented Jan 18, 2024

Same problem, istanbul/nyc/storybook was missing files in the coverage report. Pinning @storybook/react-webpack5 to 7.5.3 worked.

@zeroliu
Copy link

zeroliu commented Mar 26, 2024

same issue for @storybook/react-vite 7.6.16

@kaidjohnson
Copy link

Looks like this change might be responsible.

From https://storybook.js.org/docs/api/main-config-babel#babelconfig

The options provided by Babel are only applicable if you've enabled the @storybook/addon-webpack5-compiler-babel addon.

We added @storybook/addon-webpack5-compiler-babel and coverage issues were fixed with 7.6.14

@supersonicclay
Copy link

supersonicclay commented Jun 27, 2024

Same issue with @storybook/react-vite: 8.1.10. I am not using @storybook/react-webpack5 at all.

If my component looks like this I get coverage:

export function Greeting({ name }: { name?: string }) {
  if (name) {
    return `Hello ${name}!`;
  }
  return 'Hello!';
}

But if my component looks like this I get no coverage:

export function DomactInfoCard({ name }: { name?: string }) {
  if (name) {
    return <div>Hello {name}!</div>;
  }
  return <div>Hello!</div>;
}

@richardansell
Copy link

richardansell commented Jun 27, 2024

Getting the same issue with 8.1.10. Will try downgrading Vite version to see if it has any effect.

Update: Managed to solve this issue using the @vitejs/plugin-react-swc as my project was previously configured using the non swc plugin following the default config setup. All coverage is now reporting as expected 👍

@supersonicclay
Copy link

I was actually able to fix it by upgrading everything in my project with npx sb@latest upgrade.

Relevant versions:

  • storybook: 8.1.11
  • @storybook/react-vite: 8.1.11
  • @storybook/addon-coverage: 1.0.4
  • @nx/storybook: 19.3.2
  • @storybook/addon-coverage/node_modules/istanbul-lib-instrument: 6.0.2

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

No branches or pull requests

6 participants