@visual-regression-tracker/agent-cypress 5.5.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 +24 -13
- package/dist/commands.js +3 -1
- package/dist/plugin.js +15 -57
- package/dist/utils.d.ts +2 -3
- package/dist/utils.js +15 -27
- 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
|
|
|
@@ -126,20 +131,25 @@ cy.vrtTrack("Whole page with default params");
|
|
|
126
131
|
|
|
127
132
|
cy.get("#navbar").vrtTrack("Separate element with default params");
|
|
128
133
|
|
|
129
|
-
cy.vrtTrack(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
+
);
|
|
142
151
|
```
|
|
152
|
+
|
|
143
153
|
##### options (optional)
|
|
144
154
|
|
|
145
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)
|
|
@@ -149,6 +159,7 @@ Viewport is taken from `Cypress.config()`, if option is not set
|
|
|
149
159
|
Browser is taken from `Cypress.browser.name`
|
|
150
160
|
|
|
151
161
|
##### errorCallbak (optional)
|
|
162
|
+
|
|
152
163
|
Allows you to define a callback that receives the error for custom side-effects.
|
|
153
164
|
|
|
154
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.
|
package/dist/commands.js
CHANGED
|
@@ -27,7 +27,9 @@ var addVrtTrackCommand = function () {
|
|
|
27
27
|
return Cypress.Commands.add("vrtTrack", {
|
|
28
28
|
prevSubject: ["optional", "element", "window", "document"],
|
|
29
29
|
}, function (subject, name, options, errorCallback) {
|
|
30
|
-
(0, utils_1.
|
|
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/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, errorCallback?: ((err: string) => boolean) | undefined) => 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,35 +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
|
-
|
|
53
|
-
|
|
54
|
-
(0, exports.log)("Diff found... Remaining retry attempts **".concat(retryLimit, "**"));
|
|
55
|
-
return (0, exports.trackWithRetry)(trackFn, shouldStopFn, onStopFn, retryLimit - 1);
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
exports.trackWithRetry = trackWithRetry;
|
|
59
|
-
var checkResult = function (result, errorCallback) { return cy.task("VRT_PROCESS_ERROR_RESULT", result, { log: false }).then(function (err) {
|
|
60
|
-
if (err && errorCallback) {
|
|
61
|
-
if (errorCallback(err)) {
|
|
62
|
-
return;
|
|
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
|
+
}
|
|
63
55
|
}
|
|
56
|
+
(0, exports.handleError)(result);
|
|
64
57
|
}
|
|
65
|
-
(0, exports.handleError)(err);
|
|
66
|
-
}); };
|
|
67
|
-
exports.checkResult = checkResult;
|
|
68
|
-
var shouldStopRetry = function (result) {
|
|
69
|
-
return (result === null || result === void 0 ? void 0 : result.status) !== sdk_js_1.TestStatus.unresolved;
|
|
70
58
|
};
|
|
71
|
-
exports.
|
|
59
|
+
exports.checkResult = checkResult;
|
|
72
60
|
var trackImage = function (subject, name, options) {
|
|
73
61
|
var imagePath;
|
|
74
62
|
var pixelRatio;
|
|
@@ -81,17 +69,17 @@ var trackImage = function (subject, name, options) {
|
|
|
81
69
|
} }))
|
|
82
70
|
.then(function () { return (0, exports.log)("tracking ".concat(name)); })
|
|
83
71
|
.then(function () {
|
|
84
|
-
return cy.task("
|
|
72
|
+
return cy.task("VRT_TRACK", __assign(__assign({}, (0, exports.toTestRunDto)({ name: name, pixelRatio: pixelRatio, options: options })), { imagePath: imagePath }), { log: false });
|
|
85
73
|
});
|
|
86
74
|
};
|
|
87
75
|
exports.trackImage = trackImage;
|
|
88
76
|
var trackBuffer = function (name, imageBuffer, options) {
|
|
89
77
|
(0, exports.log)("tracking ".concat(name));
|
|
90
|
-
return cy.task("
|
|
78
|
+
return cy.task("VRT_TRACK", __assign(__assign({}, (0, exports.toTestRunDto)({ name: name, options: options })), { imageBuffer: imageBuffer }), { log: false });
|
|
91
79
|
};
|
|
92
80
|
exports.trackBuffer = trackBuffer;
|
|
93
81
|
var trackBase64 = function (name, imageBase64, options) {
|
|
94
82
|
(0, exports.log)("tracking ".concat(name));
|
|
95
|
-
return cy.task("
|
|
83
|
+
return cy.task("VRT_TRACK", __assign(__assign({}, (0, exports.toTestRunDto)({ name: name, options: options })), { imageBase64: imageBase64 }), { log: false });
|
|
96
84
|
};
|
|
97
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",
|