Replies: 4 comments 7 replies
-
Hi @lucasmuna! I'm Dosu and I’m helping the storybook team. This kind of inconsistent coverage is a known challenge when running multiple Vitest projects with different environments (like browser/playwright for Storybook and jsdom for unit tests). The main reasons are:
Best practice is to run coverage for each project independently (e.g., Also, make sure your Vite config is merged correctly for both projects, and that global styles, assets, and setup files are loaded identically in both environments to minimize discrepancies see discussion. Recent Storybook releases have improved config merging for addon-vitest, but some setups still require manual intervention, especially with custom plugins see issue. If you continue to see issues, consider isolating your test configs further (e.g., separate To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Hi @lucasmuna! My name is Reuben, and I'm one of the Solutions Engineers at Chromatic and Storybook. |
Beta Was this translation helpful? Give feedback.
-
Hi @lucasmuna Do you encounter the same inconsistencies if you just run |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Hello,
While adding unit tests as a new
vitest
project calledunit
I saw that my coverage actually got worse than just running the "standard" storybook project.So, if I run
npx vitest --project storybook --coverage --run
I get the expected coverage report (without unit tests), but, if I run all tests withnpx vitest --coverage --run
I get worse coverage results. By worse I mean, code that was marked as covered becomes marked as uncovered.My first guess is that I messed up with the configuration, but I failed to find something. My second guess is that each project report is somewhat different, as
storybook
uses browser/playwright env andunit
uses jsdom, but could not find anything as well.As additional info, if I add the unit tests file patterns to
.storybook/main.ts
configstories
, then I have the expected coverage result, but, I cannot run storybook anymore because it throwsError: Invariant failed: No matching indexer found for
. The error is expected because these unit tests are not stories, but the coverage behavior is interesting.Any ideas are welcomed.
Additional information
My
vitest.config.ts
:npx vitest --project storybook --coverage --run
npx vitest --coverage --run
(sostorybook
andunit
projects)npx vitest --project storybook --coverage --run
with unit test file patterns under.storybook/main.ts
configstories
Create a reproduction
No response
Beta Was this translation helpful? Give feedback.
All reactions