storybook/docs/snippets/common/storybook-storyshots-custom-directory.js.mdx
2021-05-06 21:05:56 +01:00

25 lines
718 B
Plaintext

```js
// storybook.test.js
import path from 'path';
import initStoryshots from '@storybook/addon-storyshots';
// The required import from the @storybook/addon-storyshots-puppeteer addon
import { imageSnapshot } from '@storybook/addon-storyshots-puppeteer';
// Function to customize the snapshot location
const getMatchOptions = ({ context: { fileName } }) => {
// Generates a custom path based on the file name and the custom directory.
const snapshotPath = path.join(path.dirname(fileName), 'your-custom-directory');
return { customSnapshotsDir: snapshotPath };
};
initStoryshots({
// your own configuration
test: imageSnapshot({
// invoke the function above here
getMatchOptions,
}),
});
```