@visual-regression-tracker/agent-cypress 5.4.0 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +0 -3
- package/.github/workflows/release.yml +0 -3
- package/README.md +32 -12
- package/dist/commands.js +4 -2
- package/dist/index.d.ts +1 -1
- package/dist/plugin.js +15 -57
- package/dist/utils.d.ts +2 -3
- package/dist/utils.js +15 -22
- package/package.json +2 -3
package/.github/workflows/ci.yml
CHANGED
package/README.md
CHANGED
|
@@ -70,6 +70,10 @@ module.exports = (on, config) => {
|
|
|
70
70
|
// Required
|
|
71
71
|
"branchName": "develop",
|
|
72
72
|
|
|
73
|
+
// Branch with baseline
|
|
74
|
+
// Optional - when not set, main branch from project settings is used
|
|
75
|
+
"baselineBranchName": "release",
|
|
76
|
+
|
|
73
77
|
// Log errors instead of throwing exceptions
|
|
74
78
|
// Optional - default false
|
|
75
79
|
"enableSoftAssert": true,
|
|
@@ -108,6 +112,7 @@ VRT_PROJECT="Default project"
|
|
|
108
112
|
VRT_APIKEY="tXZVHX0EA4YQM1MGDD"
|
|
109
113
|
VRT_CIBUILDID="commit_sha"
|
|
110
114
|
VRT_BRANCHNAME="develop"
|
|
115
|
+
VRT_BASELINEBRANCHNAME="release"
|
|
111
116
|
VRT_ENABLESOFTASSERT=true
|
|
112
117
|
```
|
|
113
118
|
|
|
@@ -121,29 +126,44 @@ cy.vrtStart();
|
|
|
121
126
|
|
|
122
127
|
### Assert
|
|
123
128
|
|
|
124
|
-
All `options` from `screenshot` command are also supported [more details](https://docs.cypress.io/api/commands/screenshot.html#Arguments)
|
|
125
|
-
|
|
126
129
|
```js
|
|
127
130
|
cy.vrtTrack("Whole page with default params");
|
|
128
131
|
|
|
129
132
|
cy.get("#navbar").vrtTrack("Separate element with default params");
|
|
130
133
|
|
|
131
|
-
cy.vrtTrack(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
134
|
+
cy.vrtTrack(
|
|
135
|
+
"Whole page with additional options",
|
|
136
|
+
{
|
|
137
|
+
viewport: "1920x1080",
|
|
138
|
+
os: "MacOS",
|
|
139
|
+
device: "Cloud agent",
|
|
140
|
+
customTags: "Cloud, DarkTheme, Auth",
|
|
141
|
+
diffTollerancePercent: 1,
|
|
142
|
+
ignoreAreas: [{ x: 1, y: 2, width: 100, height: 200 }],
|
|
143
|
+
retryLimit: 2,
|
|
144
|
+
keepScreenshot: false, // Keep screenshot local copy, false by default
|
|
145
|
+
},
|
|
146
|
+
(err) => {
|
|
147
|
+
console.log("Screenshot has diff with baseline", err);
|
|
148
|
+
return true; // Skip failing test
|
|
149
|
+
}
|
|
150
|
+
);
|
|
141
151
|
```
|
|
142
152
|
|
|
153
|
+
##### options (optional)
|
|
154
|
+
|
|
155
|
+
Allows to set options for taking screenshot. All `options` from `screenshot` command are also supported [more details](https://docs.cypress.io/api/commands/screenshot.html#Arguments)
|
|
156
|
+
|
|
143
157
|
Viewport is taken from `Cypress.config()`, if option is not set
|
|
144
158
|
|
|
145
159
|
Browser is taken from `Cypress.browser.name`
|
|
146
160
|
|
|
161
|
+
##### errorCallbak (optional)
|
|
162
|
+
|
|
163
|
+
Allows you to define a callback that receives the error for custom side-effects.
|
|
164
|
+
|
|
165
|
+
Also allows to override assertion policy. When callback returns `true` this acts similar to `enableSoftAssertions` option in config, but allows to enable soft assertion only for one specific screenshot.
|
|
166
|
+
|
|
147
167
|
### Teadown
|
|
148
168
|
|
|
149
169
|
```js
|
package/dist/commands.js
CHANGED
|
@@ -26,8 +26,10 @@ exports.addVrtStopCommand = addVrtStopCommand;
|
|
|
26
26
|
var addVrtTrackCommand = function () {
|
|
27
27
|
return Cypress.Commands.add("vrtTrack", {
|
|
28
28
|
prevSubject: ["optional", "element", "window", "document"],
|
|
29
|
-
}, function (subject, name, options) {
|
|
30
|
-
(0, utils_1.
|
|
29
|
+
}, function (subject, name, options, errorCallback) {
|
|
30
|
+
(0, utils_1.trackImage)(subject, name, options).then(function (result) {
|
|
31
|
+
return (0, utils_1.checkResult)(result, errorCallback);
|
|
32
|
+
});
|
|
31
33
|
});
|
|
32
34
|
};
|
|
33
35
|
exports.addVrtTrackCommand = addVrtTrackCommand;
|
package/dist/index.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ declare namespace Cypress {
|
|
|
23
23
|
*/
|
|
24
24
|
vrtTrack(name: string, options?: Partial<Loggable & Timeoutable & ScreenshotOptions & TrackOptions & {
|
|
25
25
|
keepScreenshot?: boolean;
|
|
26
|
-
}
|
|
26
|
+
}>, errorCallback?: (err: string) => boolean): Chainable<null>;
|
|
27
27
|
vrtTrackBuffer(name: string, imageBuffer: Buffer, options?: Partial<Loggable & Timeoutable & ScreenshotOptions & TrackOptions>): Chainable<null>;
|
|
28
28
|
vrtTrackBase64(name: string, imageBase64: string, options?: Partial<Loggable & Timeoutable & ScreenshotOptions & TrackOptions>): Chainable<null>;
|
|
29
29
|
vrtStart(): null;
|
package/dist/plugin.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -97,56 +86,25 @@ function addVisualRegressionTrackerPlugin(on, config) {
|
|
|
97
86
|
}
|
|
98
87
|
});
|
|
99
88
|
}); },
|
|
100
|
-
_a["
|
|
101
|
-
var
|
|
102
|
-
|
|
103
|
-
|
|
89
|
+
_a["VRT_TRACK"] = function (props) { return __awaiter(_this, void 0, void 0, function () {
|
|
90
|
+
var err_3;
|
|
91
|
+
var _a;
|
|
92
|
+
return __generator(this, function (_b) {
|
|
93
|
+
switch (_b.label) {
|
|
104
94
|
case 0:
|
|
105
|
-
|
|
106
|
-
return [4 /*yield*/, vrt
|
|
107
|
-
case 1:
|
|
108
|
-
|
|
109
|
-
|
|
95
|
+
_b.trys.push([0, 2, 3, 4]);
|
|
96
|
+
return [4 /*yield*/, vrt.track(props, props === null || props === void 0 ? void 0 : props.retryLimit)];
|
|
97
|
+
case 1: return [2 /*return*/, _b.sent()];
|
|
98
|
+
case 2:
|
|
99
|
+
err_3 = _b.sent();
|
|
100
|
+
return [2 /*return*/, (_a = err_3.message) !== null && _a !== void 0 ? _a : err_3];
|
|
101
|
+
case 3:
|
|
102
|
+
if (!props.keepScreenshot && props.imagePath) {
|
|
110
103
|
(0, fs_1.unlinkSync)(props.imagePath);
|
|
111
104
|
}
|
|
112
|
-
return [
|
|
113
|
-
|
|
114
|
-
});
|
|
115
|
-
}); },
|
|
116
|
-
_a["VRT_TRACK_BUFFER_MULTIPART"] = function (props) { return __awaiter(_this, void 0, void 0, function () {
|
|
117
|
-
var data, result;
|
|
118
|
-
return __generator(this, function (_a) {
|
|
119
|
-
switch (_a.label) {
|
|
120
|
-
case 0:
|
|
121
|
-
data = (0, sdk_js_1.bufferDtoToFormData)(__assign(__assign({}, props), { buildId: vrt.buildId, projectId: vrt.projectId, branchName: vrt.config.branchName }));
|
|
122
|
-
return [4 /*yield*/, vrt["submitTestRunMultipart"](data)];
|
|
123
|
-
case 1:
|
|
124
|
-
result = _a.sent();
|
|
125
|
-
return [2 /*return*/, result];
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
}); },
|
|
129
|
-
_a["VRT_TRACK_IMAGE_BASE64"] = function (props) { return __awaiter(_this, void 0, void 0, function () {
|
|
130
|
-
var result;
|
|
131
|
-
return __generator(this, function (_a) {
|
|
132
|
-
switch (_a.label) {
|
|
133
|
-
case 0: return [4 /*yield*/, vrt["submitTestRunBase64"](props)];
|
|
134
|
-
case 1:
|
|
135
|
-
result = _a.sent();
|
|
136
|
-
return [2 /*return*/, result];
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
}); },
|
|
140
|
-
_a["VRT_PROCESS_ERROR_RESULT"] = function (testRunResult) { return __awaiter(_this, void 0, void 0, function () {
|
|
141
|
-
var _a;
|
|
142
|
-
return __generator(this, function (_b) {
|
|
143
|
-
try {
|
|
144
|
-
vrt["processTestRun"](testRunResult);
|
|
145
|
-
}
|
|
146
|
-
catch (err) {
|
|
147
|
-
return [2 /*return*/, (_a = err.message) !== null && _a !== void 0 ? _a : err];
|
|
105
|
+
return [7 /*endfinally*/];
|
|
106
|
+
case 4: return [2 /*return*/];
|
|
148
107
|
}
|
|
149
|
-
return [2 /*return*/, null];
|
|
150
108
|
});
|
|
151
109
|
}); },
|
|
152
110
|
_a));
|
package/dist/utils.d.ts
CHANGED
|
@@ -17,10 +17,9 @@ export declare const toTestRunDto: ({ name, pixelRatio, options, }: {
|
|
|
17
17
|
diffTollerancePercent: any;
|
|
18
18
|
ignoreAreas: any;
|
|
19
19
|
keepScreenshot: any;
|
|
20
|
+
retryLimit: any;
|
|
20
21
|
};
|
|
21
|
-
export declare const
|
|
22
|
-
export declare const checkResult: (result: TestRunResponse) => Cypress.Chainable<unknown>;
|
|
23
|
-
export declare const shouldStopRetry: (result: TestRunResponse) => boolean;
|
|
22
|
+
export declare const checkResult: (result: TestRunResponse | string, errorCallback?: ((err: string) => boolean) | undefined) => void;
|
|
24
23
|
export declare const trackImage: (subject: any, name: string, options: any) => Cypress.Chainable<TestRunResponse>;
|
|
25
24
|
export declare const trackBuffer: (name: string, imageBuffer: Buffer, options: any) => Cypress.Chainable<TestRunResponse>;
|
|
26
25
|
export declare const trackBase64: (name: string, imageBase64: string, options: any) => Cypress.Chainable<TestRunResponse>;
|
package/dist/utils.js
CHANGED
|
@@ -12,8 +12,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
12
12
|
return __assign.apply(this, arguments);
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.trackBase64 = exports.trackBuffer = exports.trackImage = exports.
|
|
16
|
-
var sdk_js_1 = require("@visual-regression-tracker/sdk-js");
|
|
15
|
+
exports.trackBase64 = exports.trackBuffer = exports.trackImage = exports.checkResult = exports.toTestRunDto = exports.handleError = exports.log = void 0;
|
|
17
16
|
var log = function (message) {
|
|
18
17
|
return Cypress.log({
|
|
19
18
|
name: "Visual Regression Tracker",
|
|
@@ -40,30 +39,24 @@ var toTestRunDto = function (_a) {
|
|
|
40
39
|
customTags: options === null || options === void 0 ? void 0 : options.customTags,
|
|
41
40
|
diffTollerancePercent: options === null || options === void 0 ? void 0 : options.diffTollerancePercent,
|
|
42
41
|
ignoreAreas: options === null || options === void 0 ? void 0 : options.ignoreAreas,
|
|
42
|
+
// next two properties actually do not belong to TestRunDto and ideally should be removed from this object
|
|
43
43
|
keepScreenshot: options === null || options === void 0 ? void 0 : options.keepScreenshot,
|
|
44
|
+
retryLimit: options === null || options === void 0 ? void 0 : options.retryLimit,
|
|
44
45
|
});
|
|
45
46
|
};
|
|
46
47
|
exports.toTestRunDto = toTestRunDto;
|
|
47
|
-
var
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
var checkResult = function (result, errorCallback) {
|
|
49
|
+
if (typeof result === "string") {
|
|
50
|
+
// . this is an error message
|
|
51
|
+
if (errorCallback) {
|
|
52
|
+
if (errorCallback(result)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
53
55
|
}
|
|
54
|
-
(0, exports.
|
|
55
|
-
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
exports.trackWithRetry = trackWithRetry;
|
|
59
|
-
var checkResult = function (result) {
|
|
60
|
-
return cy.task("VRT_PROCESS_ERROR_RESULT", result, { log: false }).then(exports.handleError);
|
|
56
|
+
(0, exports.handleError)(result);
|
|
57
|
+
}
|
|
61
58
|
};
|
|
62
59
|
exports.checkResult = checkResult;
|
|
63
|
-
var shouldStopRetry = function (result) {
|
|
64
|
-
return (result === null || result === void 0 ? void 0 : result.status) !== sdk_js_1.TestStatus.unresolved;
|
|
65
|
-
};
|
|
66
|
-
exports.shouldStopRetry = shouldStopRetry;
|
|
67
60
|
var trackImage = function (subject, name, options) {
|
|
68
61
|
var imagePath;
|
|
69
62
|
var pixelRatio;
|
|
@@ -76,17 +69,17 @@ var trackImage = function (subject, name, options) {
|
|
|
76
69
|
} }))
|
|
77
70
|
.then(function () { return (0, exports.log)("tracking ".concat(name)); })
|
|
78
71
|
.then(function () {
|
|
79
|
-
return cy.task("
|
|
72
|
+
return cy.task("VRT_TRACK", __assign(__assign({}, (0, exports.toTestRunDto)({ name: name, pixelRatio: pixelRatio, options: options })), { imagePath: imagePath }), { log: false });
|
|
80
73
|
});
|
|
81
74
|
};
|
|
82
75
|
exports.trackImage = trackImage;
|
|
83
76
|
var trackBuffer = function (name, imageBuffer, options) {
|
|
84
77
|
(0, exports.log)("tracking ".concat(name));
|
|
85
|
-
return cy.task("
|
|
78
|
+
return cy.task("VRT_TRACK", __assign(__assign({}, (0, exports.toTestRunDto)({ name: name, options: options })), { imageBuffer: imageBuffer }), { log: false });
|
|
86
79
|
};
|
|
87
80
|
exports.trackBuffer = trackBuffer;
|
|
88
81
|
var trackBase64 = function (name, imageBase64, options) {
|
|
89
82
|
(0, exports.log)("tracking ".concat(name));
|
|
90
|
-
return cy.task("
|
|
83
|
+
return cy.task("VRT_TRACK", __assign(__assign({}, (0, exports.toTestRunDto)({ name: name, options: options })), { imageBase64: imageBase64 }), { log: false });
|
|
91
84
|
};
|
|
92
85
|
exports.trackBase64 = trackBase64;
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visual-regression-tracker/agent-cypress",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.0",
|
|
4
4
|
"description": "Visual Regression Tracker integration plugin",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "cypress run --spec 'cypress/integration/regression.spec.ts'",
|
|
9
8
|
"build": "tsc",
|
|
10
9
|
"semantic-release": "semantic-release"
|
|
11
10
|
},
|
|
@@ -25,7 +24,7 @@
|
|
|
25
24
|
},
|
|
26
25
|
"homepage": "https://github.com/Visual-Regression-Tracker/agent-cypress#readme",
|
|
27
26
|
"dependencies": {
|
|
28
|
-
"@visual-regression-tracker/sdk-js": "5.
|
|
27
|
+
"@visual-regression-tracker/sdk-js": "5.6.0"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
31
30
|
"@types/jest": "^27.4.1",
|