vitest-dev / vitest

Next generation testing framework powered by Vite.
https://vitest.dev
MIT License
12.62k stars 1.13k forks source link

[Vitest 2.x] Browser mode failure snapshots directory name can conflict with other tools #6239

Closed yannbf closed 2 weeks ago

yannbf commented 1 month ago

Describe the bug

When testing story files from Storybook using Vitest (e.g. Button.stories.tsx), the failures generate a directory like __screenshots__/Button.stories.tsx/FailingStoryName.png:

image

However because the Storybook indexer uses globs that match *.stories.*, it ends up detecting the directory too. While Storybook could improve its matching mechanics, being able to modify the names used in the snapshots like Jest's snapshotResolver would be quite useful. There could be other tools which might conflict because of similar situations.

If Vitest appended .snap at the end of the directory name, this would also fix the issue.

Used Package Manager

npm

Validations

sheremet-va commented 1 month ago

Maybe we should just have it in the name? How do other frameworks do 🤔

sheremet-va commented 1 month ago

Looks like cypress does the same, but their screenshot folder is in the root: https://docs.cypress.io/api/commands/screenshot#Naming-conventions

Can't you just add __screenshots__ folder to ignore?

yannbf commented 2 weeks ago

Good point, I'll make sure we can handle this in Storybook! Thanks for investigating <3