Skip to content

Commit 17b87d8

Browse files
committed
Add visual testing
1 parent 212a44b commit 17b87d8

32 files changed

+188
-3
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,6 @@ sketch
261261
.history
262262
.ionide
263263

264-
# End of https://www.toptal.com/developers/gitignore/api/jetbrains+all,visualstudiocode,node,react
264+
# End of https://www.toptal.com/developers/gitignore/api/jetbrains+all,visualstudiocode,node,react
265+
266+
__snapshots__/__diff_output__/

.gitlab-ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ storybook:test:
2525
- npm ci
2626
- npm run storybook:dev &
2727
- curl --fail -sv --retry 30 --retry-delay 3 --head --retry-all-errors http://127.0.0.1:6006
28-
- npm run storybook:test -- --ci --browsers chromium firefox webkit
28+
- npm run storybook:test:all -- --ci
29+
artifacts:
30+
paths:
31+
- __snapshots__/__diff_output__
32+
expire_in: 7 days

.storybook/test-runner.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { TestRunnerConfig } from '@storybook/test-runner';
22
import { getStoryContext, waitForPageReady } from '@storybook/test-runner'
33
import { injectAxe, checkA11y, configureAxe } from 'axe-playwright';
4+
import { toMatchImageSnapshot } from 'jest-image-snapshot';
5+
6+
const customSnapshotsDir = `${process.cwd()}/__snapshots__`;
47

58
const prepareA11y = async (page) => await injectAxe(page);
69

@@ -27,11 +30,23 @@ const executeA11y = async (page, context) => {
2730
});
2831
}
2932

33+
const executeVisualTest = async (page, context) => {
34+
const image = await page.locator('#storybook-root').screenshot();
35+
expect(image).toMatchImageSnapshot({
36+
customSnapshotsDir,
37+
customSnapshotIdentifier: `${context.id}-${page.context().browser().browserType().name()}`,
38+
});
39+
}
40+
3041
const config: TestRunnerConfig = {
42+
setup() {
43+
expect.extend({ toMatchImageSnapshot });
44+
},
3145
async postVisit(page, context) {
3246
await waitForPageReady(page);
3347
await prepareA11y(page);
3448
await executeA11y(page, context);
49+
await executeVisualTest(page, context);
3550
},
3651
};
3752

33.5 KB
Loading
53 KB
Loading
32.6 KB
Loading
13.5 KB
Loading
13.6 KB
Loading
12.6 KB
Loading
16 KB
Loading

0 commit comments

Comments
 (0)