forked from readymade-ui/fullstack-web-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb-components-storyshots.test.js
37 lines (32 loc) · 1.01 KB
/
web-components-storyshots.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { join, dirname } 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 = join(
'packages',
'component',
dirname(fileName),
'__snapshots__'
);
return { customSnapshotsDir: snapshotPath };
};
// Delays snapshot, mostly for CI
const beforeScreenshot = (page, { context: { kind, story }, url }) => {
return new Promise((resolve) =>
setTimeout(() => {
resolve();
}, 500)
);
};
initStoryshots({
framework: 'web-components',
integrityOptions: { cwd: join(__dirname, 'packages', 'component') },
configPath: join(__dirname, '.storybook'),
test: imageSnapshot({
beforeScreenshot,
getMatchOptions,
}),
});