storybook: CSF stories does not work correctly with addon-storyshots multiSnapshotWithOptions option
Describe the bug I am trying out the beta for 5.2 and have converted several stories over to CSF. What i’ve found is that when running storyshots, all of the stories in the CSF style end up using the generic snapshot path/file instead of creating the snapshots adjacent to the stories.
To Reproduce Steps to reproduce the behavior:
- Run
jestwith the storyshots add on enabled and the “–ci” flag - Tests will fail because the snapshots are not in the expected location so are being considered new
Expected behavior The story should use the same location as before to store snapshots.
Code snippets
// story-snapshots.test.ts
import initStoryshots, { multiSnapshotWithOptions } from "@storybook/addon-storyshots";
initStoryshots({
test: multiSnapshotWithOptions({})
});
System: OS: Windows 10 CPU: (8) x64 Intel® Core™ i7-6820HQ CPU @ 2.70GHz Binaries: Node: 10.15.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.16.0 - ~\AppData\Roaming\npm\yarn.CMD npm: 6.10.0 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: 42.17134.1.0 npmPackages: @storybook/addon-actions: 5.2.0-beta.23 => 5.2.0-beta.23 @storybook/addon-contexts: 5.2.0-beta.23 => 5.2.0-beta.23 @storybook/addon-docs: 5.2.0-beta.23 => 5.2.0-beta.23 @storybook/addon-knobs: 5.2.0-beta.23 => 5.2.0-beta.23 @storybook/addon-storyshots: 5.2.0-beta.23 => 5.2.0-beta.23 @storybook/addon-storyshots-puppeteer: 5.2.0-beta.23 => 5.2.0-beta.23 @storybook/addon-viewport: 5.2.0-beta.23 => 5.2.0-beta.23 @storybook/addons: 5.2.0-beta.23 => 5.2.0-beta.23 @storybook/preset-scss: ^1.0.2 => 1.0.2 @storybook/react: 5.2.0-beta.23 => 5.2.0-beta.23 @storybook/source-loader: 5.2.0-beta.23 => 5.2.0-beta.23 @storybook/theming: 5.2.0-beta.23 => 5.2.0-beta.23
Additional context I did some tracing and the problem appears to be the the filename for the story is undefined when the snapshot is being validated. I’ve traced where the filename is being determined:
For CSF stories m is true here instead of an object. I believe the source may be this line here:
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 17 (13 by maintainers)
Workaround: add
{fileName: __filename}parameters to your CSF stories:UPD: Until #8000 gets merged and released, you can also copy
injectFileName.jsto your project and include it in yourjest.config.jslike that:This will add
parameters.fileNameautomaticallyYes I do
Maybe there is something that I should change additionally for
5.3?@mazikwyry Ugh, this file got filtered out of the publish. Sorry about that. I’ve fixed it here and will re-publish once it’s merged: https://github.com/storybookjs/storybook/pull/8354
cc @ndelangen @Hypnosphi