storybook/docs/snippets/common/storybook-storyshots-custom-directory.js.mdx
2022-11-17 16:33:22 +01:00

26 lines
719 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,
}),
});
```