I've been diving into Storybook recently and ran into a bit of a snag with my VueJs project. After installing Storybook and creating my first component, I noticed that my .spec files stopped working. I'm using Vitest for unit testing and V8 for coverage. The issue seems to be that coverage recognizes the store files but claims there are no tests for them—it only acknowledges the .stories files. I've attempted to create a separate vitest.config.ts for my .spec files, but that ended up breaking the coverage for my .stories when I tried running Storybook. Should I consider moving my components and Storybook to a different project altogether? Any advice on fixing this situation would be greatly appreciated!
3 Answers
Honestly, the oversight of including coverage for .stories might not be necessary. Those story files should be excluded from your unit tests and coverage checks since you're already testing the underlying components. That way, you won't run into issues with coverage reports picking up stories instead of your tests. If the addon for Vitest is causing problems, it might be worth just sticking to .spec files for your coverage and letting Storybook handle the .stories.
Yeah, you can definitely run both .stories and .spec files in the same project! It sounds like the problem lies in your configuration settings. Make sure that your Vitest configuration is set to ignore story files. You should add an exclude pattern specific for story files in your vitest.config.ts. For Storybook, double-check the main config file to ensure it's only including story files. There's no need to separate your projects; just tweak the configs so they can coexist nicely.
It’s totally doable to have both types of files in one project! Just keep in mind that the issue can often stem from how Vitest and Storybook are set up to find and run your files. Your vitest.config.ts needs to have clear include and exclude rules so that it picks up .spec files without confusing them with the .stories files. Also, Storybook shouldn’t interfere with your test runner unless there’s some overlap in the configuration. Try isolating the configs more!
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String