mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-06 06:21:23 +08:00
1.8 KiB
1.8 KiB
const { waitForPageReady } = require('@storybook/test-runner');
const { toMatchImageSnapshot } = require('jest-image-snapshot');
const customSnapshotsDir = `${process.cwd()}/__snapshots__`;
/** @type { import('@storybook/test-runner').TestRunnerConfig } */
module.exports = {
setup() {
expect.extend({ toMatchImageSnapshot });
},
async postVisit(page, context) {
// Waits for the page to be ready before taking a screenshot to ensure consistent results
await waitForPageReady(page);
// To capture a screenshot for different browsers, add page.context().browser().browserType().name() to get the browser name to prefix the file name
const image = await page.screenshot();
expect(image).toMatchImageSnapshot({
customSnapshotsDir,
customSnapshotIdentifier: context.id,
});
},
};
import { TestRunnerConfig, waitForPageReady } from '@storybook/test-runner';
import { toMatchImageSnapshot } from 'jest-image-snapshot';
const customSnapshotsDir = `${process.cwd()}/__snapshots__`;
const config: TestRunnerConfig = {
setup() {
expect.extend({ toMatchImageSnapshot });
},
async postVisit(page, context) {
// Waits for the page to be ready before taking a screenshot to ensure consistent results
await waitForPageReady(page);
// To capture a screenshot for for different browsers, add page.context().browser().browserType().name() to get the browser name to prefix the file name
const image = await page.screenshot();
expect(image).toMatchImageSnapshot({
customSnapshotsDir,
customSnapshotIdentifier: context.id,
});
},
};
export default config;