Skip to content

Commit bfb6b8f

Browse files
darioblancoamcasey
authored andcommitted
Add types for backstopjs 4.1 (DefinitelyTyped#36022)
1 parent 4b88e01 commit bfb6b8f

File tree

4 files changed

+182
-0
lines changed

4 files changed

+182
-0
lines changed

types/backstopjs/backstopjs-tests.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import backstop, { Scenario, Viewport } from 'backstopjs';
2+
3+
/** Examples inspired on https://github.com/garris/BackstopJS#integration-options-local-install */
4+
5+
backstop('approve').then(() => { }).catch(() => { });
6+
7+
backstop('init');
8+
9+
backstop('reference', {
10+
filter: 'someScenarioLabelAsRegExString'
11+
});
12+
13+
backstop('test', { config: 'custom/backstop/config.json' });
14+
15+
backstop('test', {
16+
filter: 'someScenarioLabelAsRegExString',
17+
config: {
18+
id: 'foo',
19+
scenarios: [],
20+
viewports: [],
21+
}
22+
});
23+
24+
/** Custom example */
25+
26+
const scenarios: Scenario[] = [{ label: 'fake', url: 'fakeUrl' }];
27+
const viewports: Viewport[] = [
28+
{
29+
name: 'phone',
30+
width: 320,
31+
height: 480,
32+
},
33+
{
34+
name: 'tablet',
35+
width: 1024,
36+
height: 768,
37+
},
38+
{
39+
name: 'desktop',
40+
width: 1280,
41+
height: 1024,
42+
},
43+
];
44+
backstop('test', {
45+
config: {
46+
scenarios,
47+
viewports,
48+
asyncCaptureLimit: 10,
49+
asyncCompareLimit: 100,
50+
baseUrl: 'http://fake:8080',
51+
id: 'fakeId',
52+
engine: 'puppeteer',
53+
engineOptions: {
54+
args: ['--no-sandbox'],
55+
},
56+
onReadyScript: 'fake/path',
57+
paths: {
58+
bitmaps_reference: 'fake/path',
59+
bitmaps_test: 'fake/path',
60+
html_report: 'fake/path',
61+
},
62+
report: ['browser'],
63+
},
64+
});

types/backstopjs/index.d.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Type definitions for backstopjs 4.0
2+
// Project: https://github.com/garris/backstopjs#readme
3+
// Definitions by: Darío Blanco <https://github.com/darioblanco>, MindDoc <https://github.com/minddocdev>
4+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5+
6+
export interface Config {
7+
asyncCaptureLimit?: number;
8+
asyncCompareLimit?: number;
9+
baseUrl?: string;
10+
ci?: {
11+
format?: string;
12+
testReportFileName?: string;
13+
testSuiteName?: string;
14+
};
15+
debugWindow?: boolean;
16+
debug?: boolean;
17+
engine?: 'chromy' | 'puppeteer';
18+
engineOptions?: {
19+
args: string[];
20+
chromeFlags?: string[];
21+
chromePath?: string;
22+
ignoreHTTPSErrors?: boolean;
23+
waitTimeout?: number;
24+
};
25+
id: string;
26+
onBeforeScript?: string;
27+
onReadyScript?: string;
28+
paths?: {
29+
ci_report?: string;
30+
bitmaps_reference?: string;
31+
bitmaps_test?: string;
32+
engine_scripts?: string;
33+
html_report?: string;
34+
json_report?: string;
35+
};
36+
report?: Array<'browser' | 'CI' | 'json'>;
37+
resembleOutputOptions?: { // See https://github.com/rsmbl/Resemble.js
38+
errorColor?: {
39+
red: number;
40+
green: number;
41+
blue: number;
42+
},
43+
errorType?: string;
44+
transparency?: number;
45+
ignoreAntialiasing?: boolean;
46+
};
47+
scenarios: Scenario[];
48+
viewports: Viewport[];
49+
}
50+
51+
export interface KeypressSelector {
52+
selector: string;
53+
keyPress: string;
54+
}
55+
56+
/** The Backstop test definition. See https://github.com/garris/BackstopJS#advanced-scenarios */
57+
export interface Scenario {
58+
clickSelector?: string; // Click the specified DOM element prior to screenshot
59+
clickSelectors?: string[]; // Simulates multiple sequential click interactions
60+
cookiePath?: string; // Import cookies in JSON format
61+
delay?: number; // Wait for x milliseconds
62+
expect?: number; // Use with selectorExpansion true to expect number of results found
63+
hideSelectors?: string[]; // Selectors set to visibility: hidden
64+
hoverSelector?: string; // Move pointer over the given DOM element prior to screenshot
65+
hoverSelectors?: string[]; // Simulates multiple sequential hover interactions
66+
keyPressSelector?: KeypressSelector; // Press key in the DOM element prior to screenshot
67+
keyPressSelectors?: KeypressSelector[]; // Simulates multiple sequential keypress interactions
68+
label: string; // Tag saved with your reference images
69+
misMatchThreshold?: string; // Percentage of different pixels allowed to pass test
70+
onBeforeScript?: string; // Used to set up browser state e.g. cookies
71+
onReadyScript?: string; // Used to modify UI state prior to screenshots e.g. hovers, clicks etc
72+
postInteractionWait?: number; // Wait for selector (ms) after interacting with hover or click
73+
readyEvent?: string; // Wait until this string has been logged to the console
74+
readySelector?: string; // Wait until this selector exists before continuing
75+
referenceUrl?: string; // Specify a different state or environment when creating reference
76+
removeSelectors?: string[]; // Selectors set to display: none
77+
requireSameDimensions?: boolean; // If true, any change in selector size will trigger a failure
78+
selectors?: string[]; // Selectors to capture
79+
selectorExpansion?: boolean; // If true, take screenshots of all matching selector instances
80+
scrollToSelector?: string; // Scroll the specified DOM element into view prior to screenshots
81+
url: string; // The url of your app state
82+
viewports?: Viewport[]; // Override global viewports
83+
}
84+
85+
export interface Viewport {
86+
name: 'phone' | 'tablet' | 'desktop';
87+
width: number;
88+
height: number;
89+
}
90+
91+
export default function backstop(
92+
command: 'approve' | 'init' | 'reference' | 'test',
93+
options?: { config?: Config | string, filter?: string },
94+
): Promise<void>;

types/backstopjs/tsconfig.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"lib": [
5+
"es6"
6+
],
7+
"noImplicitAny": true,
8+
"noImplicitThis": true,
9+
"strictFunctionTypes": true,
10+
"strictNullChecks": true,
11+
"baseUrl": "../",
12+
"typeRoots": [
13+
"../"
14+
],
15+
"types": [],
16+
"noEmit": true,
17+
"forceConsistentCasingInFileNames": true
18+
},
19+
"files": [
20+
"index.d.ts",
21+
"backstopjs-tests.ts"
22+
]
23+
}

types/backstopjs/tslint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "extends": "dtslint/dt.json" }

0 commit comments

Comments
 (0)