mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 11:11:53 +08:00
27 lines
702 B
Plaintext
27 lines
702 B
Plaintext
```js
|
|
// .storybook/test-runner.js
|
|
|
|
const { waitForPageReady } = require('@storybook/test-runner');
|
|
|
|
const { toMatchImageSnapshot } = require('jest-image-snapshot');
|
|
|
|
const customSnapshotsDir = `${process.cwd()}/__snapshots__`;
|
|
|
|
module.exports = {
|
|
setup() {
|
|
expect.extend({ toMatchImageSnapshot });
|
|
},
|
|
async postVisit(page, context) {
|
|
// Awaits for the page to be loaded and available including assets (e.g., fonts)
|
|
await waitForPageReady(page);
|
|
|
|
// Generates a snapshot file based on the story identifier
|
|
const image = await page.screenshot();
|
|
expect(image).toMatchImageSnapshot({
|
|
customSnapshotsDir,
|
|
customSnapshotIdentifier: context.id,
|
|
});
|
|
},
|
|
};
|
|
```
|