@storybook/addon-storyshots
Version:
Take a code snapshot of every story automatically with Jest
51 lines (43 loc) • 1.44 kB
JavaScript
import path from 'path';
import initStoryshots, { multiSnapshotWithOptions, Stories2SnapsConverter } from '../src';
/* deprecated and will be removed in Storybook 8.0 */
class AnotherStories2SnapsConverter extends Stories2SnapsConverter {
getSnapshotFileName(context) {
const { fileName, kind, name } = context;
const { dir, name: filename } = path.parse(fileName);
const uniqueName = `${filename}@${kind.replace(/ /g, '-_-')}@${name.replace(/ /g, '-_-')}`;
const { snapshotsDirName, snapshotExtension } = this.options;
return path.format({
dir: path.join(dir, snapshotsDirName),
name: uniqueName,
ext: snapshotExtension,
});
}
getPossibleStoriesFiles(storyshotFile) {
const { dir, name } = path.parse(storyshotFile);
const { storiesExtensions } = this.options;
const [fileName] = name.split('@');
return storiesExtensions.map((ext) =>
path.format({
dir: path.dirname(dir),
name: fileName,
ext,
})
);
}
}
initStoryshots({
framework: 'react',
integrityOptions: { cwd: __dirname },
stories2snapsConverter: new AnotherStories2SnapsConverter({ snapshotExtension: '.boo' }),
config: ({ configure }) =>
configure(
() => {
// eslint-disable-next-line global-require
require('./exported_metadata/Extra.stories.jsx');
},
module,
false
),
test: multiSnapshotWithOptions(),
});