@visual-regression-tracker/agent-cypress 5.2.0 → 5.5.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/release.yml +1 -1
- package/README.md +12 -2
- package/dist/commands.js +2 -2
- package/dist/index.d.ts +5 -2
- package/dist/plugin.js +3 -1
- package/dist/utils.d.ts +3 -2
- package/dist/utils.js +14 -8
- package/package.json +11 -9
package/README.md
CHANGED
|
@@ -121,8 +121,6 @@ cy.vrtStart();
|
|
|
121
121
|
|
|
122
122
|
### Assert
|
|
123
123
|
|
|
124
|
-
All `options` from `screenshot` command are also supported [more details](https://docs.cypress.io/api/commands/screenshot.html#Arguments)
|
|
125
|
-
|
|
126
124
|
```js
|
|
127
125
|
cy.vrtTrack("Whole page with default params");
|
|
128
126
|
|
|
@@ -136,13 +134,25 @@ cy.vrtTrack("Whole page with additional options", {
|
|
|
136
134
|
diffTollerancePercent: 1,
|
|
137
135
|
ignoreAreas: [{ x: 1, y: 2, width: 100, height: 200 }],
|
|
138
136
|
retryLimit: 2,
|
|
137
|
+
keepScreenshot: false, // Keep screenshot local copy, false by default
|
|
138
|
+
}, (err)=>{
|
|
139
|
+
console.log('Screenshot has diff with baseline', err);
|
|
140
|
+
return true; // Skip failing test
|
|
139
141
|
});
|
|
140
142
|
```
|
|
143
|
+
##### options (optional)
|
|
144
|
+
|
|
145
|
+
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)
|
|
141
146
|
|
|
142
147
|
Viewport is taken from `Cypress.config()`, if option is not set
|
|
143
148
|
|
|
144
149
|
Browser is taken from `Cypress.browser.name`
|
|
145
150
|
|
|
151
|
+
##### errorCallbak (optional)
|
|
152
|
+
Allows you to define a callback that receives the error for custom side-effects.
|
|
153
|
+
|
|
154
|
+
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.
|
|
155
|
+
|
|
146
156
|
### Teadown
|
|
147
157
|
|
|
148
158
|
```js
|
package/dist/commands.js
CHANGED
|
@@ -26,8 +26,8 @@ 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.trackWithRetry)(function () { return (0, utils_1.trackImage)(subject, name, options); }, function (result) { return (0, utils_1.shouldStopRetry)(result); }, function (result) { return (0, utils_1.checkResult)(result); }, options === null || options === void 0 ? void 0 : options.retryLimit);
|
|
29
|
+
}, function (subject, name, options, errorCallback) {
|
|
30
|
+
(0, utils_1.trackWithRetry)(function () { return (0, utils_1.trackImage)(subject, name, options); }, function (result) { return (0, utils_1.shouldStopRetry)(result); }, function (result) { return (0, utils_1.checkResult)(result, errorCallback); }, options === null || options === void 0 ? void 0 : options.retryLimit);
|
|
31
31
|
});
|
|
32
32
|
};
|
|
33
33
|
exports.addVrtTrackCommand = addVrtTrackCommand;
|
package/dist/index.d.ts
CHANGED
|
@@ -17,10 +17,13 @@ declare namespace Cypress {
|
|
|
17
17
|
* ignoreAreas: [
|
|
18
18
|
* {x: 1, y: 2, width: 100, height: 200}
|
|
19
19
|
* ],
|
|
20
|
-
* retryLimit: 5
|
|
20
|
+
* retryLimit: 5,
|
|
21
|
+
* keepScreenshot: false,
|
|
21
22
|
* })
|
|
22
23
|
*/
|
|
23
|
-
vrtTrack(name: string, options?: Partial<Loggable & Timeoutable & ScreenshotOptions & TrackOptions
|
|
24
|
+
vrtTrack(name: string, options?: Partial<Loggable & Timeoutable & ScreenshotOptions & TrackOptions & {
|
|
25
|
+
keepScreenshot?: boolean;
|
|
26
|
+
}>, errorCallback?: (err: string) => boolean): Chainable<null>;
|
|
24
27
|
vrtTrackBuffer(name: string, imageBuffer: Buffer, options?: Partial<Loggable & Timeoutable & ScreenshotOptions & TrackOptions>): Chainable<null>;
|
|
25
28
|
vrtTrackBase64(name: string, imageBase64: string, options?: Partial<Loggable & Timeoutable & ScreenshotOptions & TrackOptions>): Chainable<null>;
|
|
26
29
|
vrtStart(): null;
|
package/dist/plugin.js
CHANGED
|
@@ -106,7 +106,9 @@ function addVisualRegressionTrackerPlugin(on, config) {
|
|
|
106
106
|
return [4 /*yield*/, vrt["submitTestRunMultipart"](data)];
|
|
107
107
|
case 1:
|
|
108
108
|
result = _a.sent();
|
|
109
|
-
|
|
109
|
+
if (!props.keepScreenshot) {
|
|
110
|
+
(0, fs_1.unlinkSync)(props.imagePath);
|
|
111
|
+
}
|
|
110
112
|
return [2 /*return*/, result];
|
|
111
113
|
}
|
|
112
114
|
});
|
package/dist/utils.d.ts
CHANGED
|
@@ -16,9 +16,10 @@ export declare const toTestRunDto: ({ name, pixelRatio, options, }: {
|
|
|
16
16
|
customTags: any;
|
|
17
17
|
diffTollerancePercent: any;
|
|
18
18
|
ignoreAreas: any;
|
|
19
|
+
keepScreenshot: any;
|
|
19
20
|
};
|
|
20
|
-
export declare const trackWithRetry: (trackFn: () => Cypress.Chainable<TestRunResponse>, shouldStopFn: (result: TestRunResponse) => boolean, onStopFn: (result: TestRunResponse) => Cypress.Chainable<unknown>, retryLimit?: number) =>
|
|
21
|
-
export declare const checkResult: (result: TestRunResponse) => Cypress.Chainable<unknown>;
|
|
21
|
+
export declare const trackWithRetry: (trackFn: () => Cypress.Chainable<TestRunResponse>, shouldStopFn: (result: TestRunResponse) => boolean, onStopFn: (result: TestRunResponse) => Cypress.Chainable<unknown>, retryLimit?: number) => unknown;
|
|
22
|
+
export declare const checkResult: (result: TestRunResponse, errorCallback?: ((err: string) => boolean) | undefined) => Cypress.Chainable<unknown>;
|
|
22
23
|
export declare const shouldStopRetry: (result: TestRunResponse) => boolean;
|
|
23
24
|
export declare const trackImage: (subject: any, name: string, options: any) => Cypress.Chainable<TestRunResponse>;
|
|
24
25
|
export declare const trackBuffer: (name: string, imageBuffer: Buffer, options: any) => Cypress.Chainable<TestRunResponse>;
|
package/dist/utils.js
CHANGED
|
@@ -34,12 +34,13 @@ var toTestRunDto = function (_a) {
|
|
|
34
34
|
return ({
|
|
35
35
|
name: name,
|
|
36
36
|
browser: Cypress.browser.name,
|
|
37
|
-
viewport: (_b = options === null || options === void 0 ? void 0 : options.viewport) !== null && _b !== void 0 ? _b : Cypress.config("viewportWidth") * pixelRatio
|
|
37
|
+
viewport: (_b = options === null || options === void 0 ? void 0 : options.viewport) !== null && _b !== void 0 ? _b : "".concat(Cypress.config("viewportWidth") * pixelRatio, "x").concat(Cypress.config("viewportHeight") * pixelRatio),
|
|
38
38
|
os: options === null || options === void 0 ? void 0 : options.os,
|
|
39
39
|
device: options === null || options === void 0 ? void 0 : options.device,
|
|
40
40
|
customTags: options === null || options === void 0 ? void 0 : options.customTags,
|
|
41
41
|
diffTollerancePercent: options === null || options === void 0 ? void 0 : options.diffTollerancePercent,
|
|
42
42
|
ignoreAreas: options === null || options === void 0 ? void 0 : options.ignoreAreas,
|
|
43
|
+
keepScreenshot: options === null || options === void 0 ? void 0 : options.keepScreenshot,
|
|
43
44
|
});
|
|
44
45
|
};
|
|
45
46
|
exports.toTestRunDto = toTestRunDto;
|
|
@@ -50,14 +51,19 @@ var trackWithRetry = function (trackFn, shouldStopFn, onStopFn, retryLimit) {
|
|
|
50
51
|
onStopFn(result);
|
|
51
52
|
return;
|
|
52
53
|
}
|
|
53
|
-
(0, exports.log)("Diff found... Remaining retry attempts **"
|
|
54
|
+
(0, exports.log)("Diff found... Remaining retry attempts **".concat(retryLimit, "**"));
|
|
54
55
|
return (0, exports.trackWithRetry)(trackFn, shouldStopFn, onStopFn, retryLimit - 1);
|
|
55
56
|
});
|
|
56
57
|
};
|
|
57
58
|
exports.trackWithRetry = trackWithRetry;
|
|
58
|
-
var checkResult = function (result) {
|
|
59
|
-
|
|
60
|
-
|
|
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;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
(0, exports.handleError)(err);
|
|
66
|
+
}); };
|
|
61
67
|
exports.checkResult = checkResult;
|
|
62
68
|
var shouldStopRetry = function (result) {
|
|
63
69
|
return (result === null || result === void 0 ? void 0 : result.status) !== sdk_js_1.TestStatus.unresolved;
|
|
@@ -73,19 +79,19 @@ var trackImage = function (subject, name, options) {
|
|
|
73
79
|
pixelRatio = props.pixelRatio;
|
|
74
80
|
return options === null || options === void 0 ? void 0 : options.onAfterScreenshot;
|
|
75
81
|
} }))
|
|
76
|
-
.then(function () { return (0, exports.log)("tracking "
|
|
82
|
+
.then(function () { return (0, exports.log)("tracking ".concat(name)); })
|
|
77
83
|
.then(function () {
|
|
78
84
|
return cy.task("VRT_TRACK_IMAGE_MULTIPART", __assign(__assign({}, (0, exports.toTestRunDto)({ name: name, pixelRatio: pixelRatio, options: options })), { imagePath: imagePath }), { log: false });
|
|
79
85
|
});
|
|
80
86
|
};
|
|
81
87
|
exports.trackImage = trackImage;
|
|
82
88
|
var trackBuffer = function (name, imageBuffer, options) {
|
|
83
|
-
(0, exports.log)("tracking "
|
|
89
|
+
(0, exports.log)("tracking ".concat(name));
|
|
84
90
|
return cy.task("VRT_TRACK_BUFFER_MULTIPART", __assign(__assign({}, (0, exports.toTestRunDto)({ name: name, options: options })), { imageBuffer: imageBuffer }), { log: false });
|
|
85
91
|
};
|
|
86
92
|
exports.trackBuffer = trackBuffer;
|
|
87
93
|
var trackBase64 = function (name, imageBase64, options) {
|
|
88
|
-
(0, exports.log)("tracking "
|
|
94
|
+
(0, exports.log)("tracking ".concat(name));
|
|
89
95
|
return cy.task("VRT_TRACK_IMAGE_BASE64", __assign(__assign({}, (0, exports.toTestRunDto)({ name: name, options: options })), { imageBase64: imageBase64 }), { log: false });
|
|
90
96
|
};
|
|
91
97
|
exports.trackBase64 = trackBase64;
|
package/package.json
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visual-regression-tracker/agent-cypress",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.5.0",
|
|
4
4
|
"description": "Visual Regression Tracker integration plugin",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
5
7
|
"scripts": {
|
|
6
8
|
"test": "cypress run --spec 'cypress/integration/regression.spec.ts'",
|
|
7
9
|
"build": "tsc",
|
|
@@ -23,16 +25,16 @@
|
|
|
23
25
|
},
|
|
24
26
|
"homepage": "https://github.com/Visual-Regression-Tracker/agent-cypress#readme",
|
|
25
27
|
"dependencies": {
|
|
26
|
-
"@visual-regression-tracker/sdk-js": "5.
|
|
28
|
+
"@visual-regression-tracker/sdk-js": "5.3.0"
|
|
27
29
|
},
|
|
28
30
|
"devDependencies": {
|
|
29
|
-
"@types/jest": "^
|
|
30
|
-
"@types/node": "^
|
|
31
|
-
"cypress": "^
|
|
32
|
-
"jest": "^
|
|
33
|
-
"semantic-release": "^
|
|
34
|
-
"ts-jest": "^
|
|
35
|
-
"typescript": "^4.
|
|
31
|
+
"@types/jest": "^27.4.1",
|
|
32
|
+
"@types/node": "^17.0.23",
|
|
33
|
+
"cypress": "^9.5.2",
|
|
34
|
+
"jest": "^27.5.1",
|
|
35
|
+
"semantic-release": "^19.0.2",
|
|
36
|
+
"ts-jest": "^27.1.4",
|
|
37
|
+
"typescript": "^4.6.3"
|
|
36
38
|
},
|
|
37
39
|
"publishConfig": {
|
|
38
40
|
"access": "public"
|