DefinitelyTyped/types/backstopjs/backstopjs-tests.ts
Christopher Deutsch 6b3f9450aa Update BackstopJS types. (#37834)
* Update BackstopJS types.

Add support for `Viewport.label` which is more commonly used than `name`.
Seems to be a free form string, not a limited set of strings:
aa7de8ee05/examples/jsBasedConfig/backstopConfig.js

Looks like they may have switched from `name` to `label` in this commit:
0535303326 (diff-9e67e5c53c6a24f5b7f26f857fff03ea)

Change `misMatchThreshold` to a number:
aa7de8ee05/examples/jsBasedConfig/backstopConfig.js (L35)

* Fix version.

* I just tested this locally and you can any custom properties you like to scenarios, which is helpful for a custom onBefore script I'm working on.
2019-08-24 21:50:15 -07:00

94 lines
1.7 KiB
TypeScript

import backstop, { Scenario, Viewport } from 'backstopjs';
/** Examples inspired on https://github.com/garris/BackstopJS#integration-options-local-install */
backstop('approve').then(() => { }).catch(() => { });
backstop('init');
backstop('reference', {
filter: 'someScenarioLabelAsRegExString'
});
backstop('test', { config: 'custom/backstop/config.json' });
backstop('test', {
filter: 'someScenarioLabelAsRegExString',
config: {
id: 'foo',
scenarios: [],
viewports: [],
}
});
/** Custom example */
const scenarios: Scenario[] = [
{
label: 'Microsoft',
url: 'https://microsoft.com/',
referenceUrl: '',
readyEvent: '',
readySelector: '',
delay: 0,
hideSelectors: [],
removeSelectors: [],
hoverSelector: '',
clickSelector: '',
postInteractionWait: 0,
selectors: [],
selectorExpansion: true,
expect: 0,
misMatchThreshold: 0.1,
requireSameDimensions: true,
},
];
const viewports: Viewport[] = [
{
name: 'phone',
width: 320,
height: 480,
},
{
name: 'tablet',
width: 1024,
height: 768,
},
{
name: 'desktop',
width: 1280,
height: 1024,
},
{
label: 'tablet_v',
width: 1280,
height: 1024,
},
{
label: 'tablet_h',
width: 1280,
height: 1024,
},
];
backstop('test', {
config: {
scenarios,
viewports,
asyncCaptureLimit: 10,
asyncCompareLimit: 100,
baseUrl: 'http://fake:8080',
id: 'fakeId',
engine: 'puppeteer',
engineOptions: {
args: ['--no-sandbox'],
},
onReadyScript: 'fake/path',
paths: {
bitmaps_reference: 'fake/path',
bitmaps_test: 'fake/path',
html_report: 'fake/path',
},
report: ['browser'],
},
});