-
Notifications
You must be signed in to change notification settings - Fork 9
/
commands.ts
101 lines (97 loc) · 2.34 KB
/
commands.ts
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* global Cypress, cy */
export const addVrtStartCommand = () => {
Cypress.Commands.add(
"vrtStart",
{
prevSubject: ["optional"],
},
() => {
cy.task("VRT_START", {}, { log: false })
.then((err) => {
if (err) {
throw new Error(err);
}
})
.then(() =>
Cypress.log({
name: "Visual Regression Tracker",
displayName: "VRT",
message: "Started",
})
);
}
);
};
export const addVrtStopCommand = () => {
Cypress.Commands.add(
"vrtStop",
{
prevSubject: ["optional"],
},
() => {
cy.task("VRT_STOP", {}, { log: false })
.then((err) => {
if (err) {
throw new Error(err);
}
})
.then(() =>
Cypress.log({
name: "Visual Regression Tracker",
displayName: "VRT",
message: "Stopped",
})
);
}
);
};
export const addVrtTrackCommand = () =>
Cypress.Commands.add(
"vrtTrack",
{
prevSubject: ["optional", "element", "window", "document"],
},
(subject, name, options) => {
let imagePath: string;
let pixelRatio: number;
const target = subject ? cy.wrap(subject) : cy;
target
.screenshot(name, {
...options,
onAfterScreenshot: (el, props) => {
imagePath = props.path;
pixelRatio = props.pixelRatio;
return options?.onAfterScreenshot;
},
})
.then(() => cy.task("ENCODE_IMAGE", { imagePath }, { log: false }))
.then((imageBase64) =>
cy.task(
"TRACK_IMAGE",
{
name,
imageBase64,
browser: Cypress.browser.name,
pixelRatio,
os: options?.os,
device: options?.device,
diffTollerancePercent: options?.diffTollerancePercent,
ignoreAreas: options?.ignoreAreas,
},
{ log: false }
)
)
.then((err) => {
if (err) {
throw new Error(err);
}
})
.then(() =>
Cypress.log({
name: "Visual Regression Tracker",
displayName: "VRT",
message: `tracked ${name}`,
})
);
}
);