You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

31 lines
1012 B

import type { TestRunnerConfig } 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) {
// DOM Snapshot
const elementHandler = await page.$('#storybook-root');
if (elementHandler) {
const innerHTML = await elementHandler.innerHTML();
expect(innerHTML).toMatchSnapshot();
}
else throw "cannot find storybook DOM root to take DOM screenshot"
// Image Snapshop
const image = await page.screenshot();
expect(image).toMatchImageSnapshot({
customSnapshotsDir,
customSnapshotIdentifier: context.id,
comparisonMethod: 'ssim',
failureThresholdType: 'percent',
failureThreshold: 0.002,
});
},
};
export default config;