-
-
Notifications
You must be signed in to change notification settings - Fork 142
/
examples.test.js
61 lines (56 loc) 路 1.58 KB
/
examples.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import puppeteer from 'puppeteer';
import path from 'path';
// We do screenshots against the static build of the storybook.
// For this test to be meaningful, you must build the static version of the storybook *before* running this test suite.
const pathToVueKitchenSink = path.join(
__dirname,
'..',
'examples/vue-kitchen-sink/storybook-static/index.html'
);
const pathToAngularKitchenSink = path.join(
__dirname,
'..',
'examples/angular-cli/storybook-static/index.html'
);
const pathToCraKitchenSink = path.join(
__dirname,
'..',
'examples/cra-kitchen-sink/storybook-static/index.html'
);
const examples = [
{
name: 'cra-kitchen-sink',
storybookUrl: pathToCraKitchenSink,
},
{
name: 'vue-kitchen-sink',
storybookUrl: pathToVueKitchenSink,
},
{
name: 'angular-cli',
storybookUrl: pathToAngularKitchenSink,
},
];
examples.forEach(({ name, storybookUrl }) => {
let browser = puppeteer.launch();
let page;
describe('sandboxes', () => {
beforeAll(async () => {
browser = await browser;
page = await browser.newPage();
await page.setViewport({ width: 1400, height: 1000 });
});
afterAll(() => {
browser.close();
});
it(`Take screenshots for '${name}'`, async () => {
await page.goto(`file:https://${storybookUrl}`);
const screenshot = await page.screenshot({ fullPage: true });
expect(screenshot).toMatchImageSnapshot({
failureThreshold: 0.04, // 4% threshold,
failureThresholdType: 'percent',
customSnapshotIdentifier: name.split('/').join('-'),
});
});
});
});