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

Improve docs: How to configure the addon to create multiple snapshot files #9774

Closed
alfechner opened this issue Feb 6, 2020 · 2 comments
Closed

Comments

@alfechner
Copy link

I'd like to configure storyshots so that it creates multiple snapshot files close to the actual story.

I found issue #887, it describes using jest-specifics-snapshop but it's for version 3.x and I cannot find any example or details in the documentation nor in the issue itself.

The documentation talks about multiSnapshotWithOptions which sounds promising but doesn't prevent my config creating one monolithic snapshot file.

My Storyshots.test.ts file looks like this:

import initStoryshots, { multiSnapshotWithOptions } from '@storybook/addon-storyshots';

initStoryshots({
    test: multiSnapshotWithOptions({}),
});

initStoryshots();

What do I miss and is it worth clarifying it to the documentation?

@gabiseabra
Copy link
Contributor

I ran into the same issue today and tried to solve it by writing my own Stories2SnapsConverter, which lead me to discover that the fileName param on getSnapshotFileName is always null, causing snapshots file resolution to fallback to the default value.
This seems to be a bug in @storybook/addon-storyshots. I've managed to find a work around by adding parameters: {fileName: __filename}} to the default export on each story.js file.

These are my dependencies:

jest@^25.1.0
@storybook/[email protected]
@storybook/addon-storyshots@^5.3.12

Login.story.js:

// ...

export default {
  parameters: {fileName: __filename},
  title: 'auth/Login'
}

export const login = () => <Login />

login.story = {name: 'default'}

snapshots.spec.js

import initStoryshots, {
  multiSnapshotWithOptions
} from '@storybook/addon-storyshots'

initStoryshots({
  framework: 'react',
  integrityOptions: {cwd: __dirname},
  test: multiSnapshotWithOptions()
})

@alfechner
Copy link
Author

I uesed storyKindRegex. I was so focused on multiSnapshotWithOptions that I overlooked it.

From the documentation about storyKindRegex :

This can be useful if you want to separate the snapshots in directories next to each component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants