@visual-regression-tracker/agent-cypress 5.5.0 → 5.7.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.
@@ -9,16 +9,15 @@ jobs:
9
9
  runs-on: ubuntu-latest
10
10
 
11
11
  steps:
12
- - uses: actions/checkout@v2
12
+ - uses: actions/checkout@v3
13
13
 
14
14
  - name: Setup Node.js environment
15
- uses: actions/setup-node@v1.4.4
15
+ uses: actions/setup-node@v3
16
+ with:
17
+ node-version: 16
16
18
 
17
19
  - name: Install npm dependencies
18
20
  run: npm ci
19
21
 
20
22
  - name: Build
21
23
  run: npm run build
22
-
23
- - name: Unit tests
24
- run: npm run test
@@ -6,15 +6,18 @@ on:
6
6
  jobs:
7
7
  release:
8
8
  name: Release
9
- runs-on: ubuntu-18.04
9
+ runs-on: ubuntu-latest
10
+
10
11
  steps:
11
12
  - name: Checkout
12
- uses: actions/checkout@v2
13
+ uses: actions/checkout@v3
13
14
  with:
14
15
  fetch-depth: 0
15
16
 
16
17
  - name: Setup Node.js environment
17
- uses: actions/setup-node@v2
18
+ uses: actions/setup-node@v3
19
+ with:
20
+ node-version: 18
18
21
 
19
22
  - name: Install dependencies
20
23
  run: npm ci
@@ -22,9 +25,6 @@ jobs:
22
25
  - name: Build
23
26
  run: npm run build
24
27
 
25
- - name: Unit tests
26
- run: npm run test
27
-
28
28
  - name: Release
29
29
  env:
30
30
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -6,13 +6,27 @@ Npm: https://www.npmjs.com/package/@visual-regression-tracker/agent-cypress
6
6
 
7
7
  ## Installation
8
8
 
9
+ Please note that the minimum supported Cypress version is [`12.17.1`, released in 10th July 2023](https://docs.cypress.io/guides/references/changelog#12-17-1).
10
+
9
11
  ### Add package
10
12
 
11
13
  `npm install @visual-regression-tracker/agent-cypress`
12
14
 
13
- ### Add command
15
+ ### Add commands
16
+
17
+ `<rootDir>/cypress/support/e2e.js` or `<rootDir>/cypress/support/component.js`
14
18
 
15
- `<rootDir>/cypress/support/commands.js`
19
+ All available commands:
20
+
21
+ ```js
22
+ import {
23
+ addVrtCommands,
24
+ } from "@visual-regression-tracker/agent-cypress";
25
+
26
+ addVrtCommands();
27
+ ```
28
+
29
+ or one by one:
16
30
 
17
31
  ```js
18
32
  import {
@@ -21,7 +35,7 @@ import {
21
35
  addVrtStopCommand,
22
36
  addVrtTrackBufferCommand,
23
37
  addVrtTrackBase64Command,
24
- } from "@visual-regression-tracker/agent-cypress/dist/commands";
38
+ } from "@visual-regression-tracker/agent-cypress";
25
39
 
26
40
  addVrtStartCommand();
27
41
  addVrtStopCommand();
@@ -32,27 +46,32 @@ addVrtTrackBase64Command();
32
46
 
33
47
  ### Add plugin
34
48
 
35
- `<rootDir>/cypress/plugins/index.js`
49
+ `<rootDir>/cypress.config.js`
36
50
 
37
51
  ```js
38
- const {
39
- addVisualRegressionTrackerPlugin,
40
- } = require("@visual-regression-tracker/agent-cypress/dist/plugin");
41
-
42
- module.exports = (on, config) => {
43
- addVisualRegressionTrackerPlugin(on, config);
44
- };
52
+ import { defineConfig } from 'cypress';
53
+ import { addVisualRegressionTrackerPlugin } from "@visual-regression-tracker/agent-cypress";
54
+
55
+ export default defineConfig({
56
+ // e2e or component, depending of testing style
57
+ e2e: {
58
+ setupNodeEvents (on, config) => {
59
+ addVisualRegressionTrackerPlugin(on, config);
60
+ }
61
+ }
62
+ });
45
63
  ```
46
64
 
47
65
  ### Configuration
48
66
 
49
- #### Update cypress config
67
+ #### Update Cypress config
50
68
 
51
- `<rootDir>/cypress.json`
69
+ `<rootDir>/cypress.config.js`
52
70
 
53
71
  ```js
54
- {
55
- "env": {
72
+ export default defineConfig({
73
+
74
+ env: {
56
75
  "visualRegressionTracker": {
57
76
  // URL where backend is running
58
77
  // Required
@@ -70,6 +89,10 @@ module.exports = (on, config) => {
70
89
  // Required
71
90
  "branchName": "develop",
72
91
 
92
+ // Branch with baseline
93
+ // Optional - when not set, main branch from project settings is used
94
+ "baselineBranchName": "release",
95
+
73
96
  // Log errors instead of throwing exceptions
74
97
  // Optional - default false
75
98
  "enableSoftAssert": true,
@@ -79,7 +102,7 @@ module.exports = (on, config) => {
79
102
  "ciBuildId": "SOME_UNIQUE_ID",
80
103
  }
81
104
  }
82
- }
105
+ });
83
106
  ```
84
107
 
85
108
  #### Or, as JSON config file `vrt.json`
@@ -108,6 +131,7 @@ VRT_PROJECT="Default project"
108
131
  VRT_APIKEY="tXZVHX0EA4YQM1MGDD"
109
132
  VRT_CIBUILDID="commit_sha"
110
133
  VRT_BRANCHNAME="develop"
134
+ VRT_BASELINEBRANCHNAME="release"
111
135
  VRT_ENABLESOFTASSERT=true
112
136
  ```
113
137
 
@@ -126,20 +150,25 @@ cy.vrtTrack("Whole page with default params");
126
150
 
127
151
  cy.get("#navbar").vrtTrack("Separate element with default params");
128
152
 
129
- cy.vrtTrack("Whole page with additional options", {
130
- viewport: "1920x1080",
131
- os: "MacOS",
132
- device: "Cloud agent",
133
- customTags: "Cloud, DarkTheme, Auth",
134
- diffTollerancePercent: 1,
135
- ignoreAreas: [{ x: 1, y: 2, width: 100, height: 200 }],
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
141
- });
153
+ cy.vrtTrack(
154
+ "Whole page with additional options",
155
+ {
156
+ viewport: "1920x1080",
157
+ os: "MacOS",
158
+ device: "Cloud agent",
159
+ customTags: "Cloud, DarkTheme, Auth",
160
+ diffTollerancePercent: 1,
161
+ ignoreAreas: [{ x: 1, y: 2, width: 100, height: 200 }],
162
+ retryLimit: 2,
163
+ keepScreenshot: false, // Keep screenshot local copy, false by default
164
+ },
165
+ (err) => {
166
+ console.log("Screenshot has diff with baseline", err);
167
+ return true; // Skip failing test
168
+ }
169
+ );
142
170
  ```
171
+
143
172
  ##### options (optional)
144
173
 
145
174
  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 +178,7 @@ Viewport is taken from `Cypress.config()`, if option is not set
149
178
  Browser is taken from `Cypress.browser.name`
150
179
 
151
180
  ##### errorCallbak (optional)
181
+
152
182
  Allows you to define a callback that receives the error for custom side-effects.
153
183
 
154
184
  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.
@@ -0,0 +1,30 @@
1
+ import { defineConfig } from 'cypress';
2
+ import { addVisualRegressionTrackerPlugin } from "./lib/plugin";
3
+
4
+ /**
5
+ * @see https://docs.cypress.io/guides/references/configuration
6
+ */
7
+ export default defineConfig({
8
+ e2e: {
9
+ baseUrl: "https://example.cypress.io",
10
+ specPattern: 'cypress/integration/*.spec.ts',
11
+
12
+ setupNodeEvents(on, config) {
13
+ // `on` is used to hook into various events Cypress emits
14
+ // `config` is the resolved Cypress config
15
+ addVisualRegressionTrackerPlugin(on, config);
16
+ },
17
+ },
18
+ video: false,
19
+ screenshotOnRunFailure: false,
20
+ retries: 0,
21
+ env: {
22
+ "visualRegressionTracker": {
23
+ "apiUrl": "http://localhost:4200",
24
+ "apiKey": "5H90NFWM6BMWWDMWKG8T11DWW22Y",
25
+ "project": "fcf9ab05-4bed-40d6-a033-c178948c9897",
26
+ "branchName": "master",
27
+ "enableSoftAssert": false
28
+ }
29
+ }
30
+ });
@@ -3,3 +3,12 @@ export declare const addVrtStopCommand: () => void;
3
3
  export declare const addVrtTrackCommand: () => void;
4
4
  export declare const addVrtTrackBufferCommand: () => void;
5
5
  export declare const addVrtTrackBase64Command: () => void;
6
+ /**
7
+ * Add all Visual Tracker commands to Cypress namespace, so that these methods become available:
8
+ * * `cy.vrtStart();`
9
+ * * `cy.vrtStop();`
10
+ * * `cy.vrtTrack();`
11
+ * * `cy.vrtTrackBuffer();`
12
+ * * `cy.vrtTrackBase64();`
13
+ */
14
+ export declare const addVrtCommands: () => void;
package/dist/commands.js CHANGED
@@ -1,53 +1,63 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addVrtTrackBase64Command = exports.addVrtTrackBufferCommand = exports.addVrtTrackCommand = exports.addVrtStopCommand = exports.addVrtStartCommand = void 0;
3
+ exports.addVrtCommands = exports.addVrtTrackBase64Command = exports.addVrtTrackBufferCommand = exports.addVrtTrackCommand = exports.addVrtStopCommand = exports.addVrtStartCommand = void 0;
4
4
  /* global Cypress, cy */
5
- var utils_1 = require("./utils");
6
- var addVrtStartCommand = function () {
7
- Cypress.Commands.add("vrtStart", {
8
- prevSubject: ["optional"],
9
- }, function () {
10
- cy.task("VRT_START", {}, { log: false })
5
+ const utils_1 = require("./utils");
6
+ const addVrtStartCommand = () => {
7
+ Cypress.Commands.add(utils_1.VRT_COMMAND_START, {
8
+ // optional: may start a chain, or use an existing chain: (dual command)
9
+ prevSubject: "optional",
10
+ }, () => {
11
+ cy.task(utils_1.VRT_TASK_START, {}, { log: false })
11
12
  .then(utils_1.handleError)
12
- .then(function () { return (0, utils_1.log)("Started"); });
13
+ .then(() => (0, utils_1.log)("Started"));
13
14
  });
14
15
  };
15
16
  exports.addVrtStartCommand = addVrtStartCommand;
16
- var addVrtStopCommand = function () {
17
- Cypress.Commands.add("vrtStop", {
18
- prevSubject: ["optional"],
19
- }, function () {
20
- cy.task("VRT_STOP", {}, { log: false })
17
+ const addVrtStopCommand = () => {
18
+ Cypress.Commands.add(utils_1.VRT_COMMAND_STOP, {
19
+ // optional: may start a chain, or use an existing chain: (dual command)
20
+ prevSubject: "optional",
21
+ }, () => {
22
+ cy.task(utils_1.VRT_TASK_STOP, {}, { log: false })
21
23
  .then(utils_1.handleError)
22
- .then(function () { return (0, utils_1.log)("Stopped"); });
24
+ .then(() => (0, utils_1.log)("Stopped"));
23
25
  });
24
26
  };
25
27
  exports.addVrtStopCommand = addVrtStopCommand;
26
- var addVrtTrackCommand = function () {
27
- return Cypress.Commands.add("vrtTrack", {
28
- prevSubject: ["optional", "element", "window", "document"],
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
- });
32
- };
28
+ const addVrtTrackCommand = () => Cypress.Commands.add(utils_1.VRT_COMMAND_TRACK, {
29
+ // https://docs.cypress.io/api/cypress-api/custom-commands#Arguments
30
+ prevSubject: ["optional", "element", "window", "document"],
31
+ }, // @ts-ignore
32
+ (subject, name, options, errorCallback) => {
33
+ (0, utils_1.trackImage)(subject, name, options).then((result) => (0, utils_1.checkResult)(result, errorCallback));
34
+ });
33
35
  exports.addVrtTrackCommand = addVrtTrackCommand;
34
- var addVrtTrackBufferCommand = function () {
35
- return Cypress.Commands.add("vrtTrackBuffer", {
36
- prevSubject: false,
37
- }, function (name, imageBuffer, options) {
38
- (0, utils_1.trackBuffer)(name, imageBuffer, options).then(function (result) {
39
- return (0, utils_1.checkResult)(result);
40
- });
41
- });
42
- };
36
+ const addVrtTrackBufferCommand = () => Cypress.Commands.add(utils_1.VRT_COMMAND_TRACK_BUFFER, {
37
+ prevSubject: false,
38
+ }, (name, imageBuffer, options) => {
39
+ (0, utils_1.trackBuffer)(name, imageBuffer, options).then((result) => (0, utils_1.checkResult)(result));
40
+ });
43
41
  exports.addVrtTrackBufferCommand = addVrtTrackBufferCommand;
44
- var addVrtTrackBase64Command = function () {
45
- return Cypress.Commands.add("vrtTrackBase64", {
46
- prevSubject: false,
47
- }, function (name, imageBase64, options) {
48
- (0, utils_1.trackBase64)(name, imageBase64, options).then(function (result) {
49
- return (0, utils_1.checkResult)(result);
50
- });
51
- });
52
- };
42
+ const addVrtTrackBase64Command = () => Cypress.Commands.add(utils_1.VRT_COMMAND_TRACK_BASE64, {
43
+ prevSubject: false,
44
+ }, (name, imageBase64, options) => {
45
+ (0, utils_1.trackBase64)(name, imageBase64, options).then((result) => (0, utils_1.checkResult)(result));
46
+ });
53
47
  exports.addVrtTrackBase64Command = addVrtTrackBase64Command;
48
+ /**
49
+ * Add all Visual Tracker commands to Cypress namespace, so that these methods become available:
50
+ * * `cy.vrtStart();`
51
+ * * `cy.vrtStop();`
52
+ * * `cy.vrtTrack();`
53
+ * * `cy.vrtTrackBuffer();`
54
+ * * `cy.vrtTrackBase64();`
55
+ */
56
+ const addVrtCommands = () => {
57
+ (0, exports.addVrtStartCommand)();
58
+ (0, exports.addVrtStopCommand)();
59
+ (0, exports.addVrtTrackCommand)();
60
+ (0, exports.addVrtTrackBufferCommand)();
61
+ (0, exports.addVrtTrackBase64Command)();
62
+ };
63
+ exports.addVrtCommands = addVrtCommands;
package/dist/index.d.ts CHANGED
@@ -1,47 +1,2 @@
1
- /// <reference types="cypress" />
2
- /// <reference types="node" />
3
- declare namespace Cypress {
4
- interface Chainable {
5
- /**
6
- * Validate image against baseline
7
- * @param name Image identifier.
8
- * @param options An object that contains one or more additional properties.
9
- *
10
- * @example
11
- * cy.vrtTrack("name")
12
- * cy.get("#id").vrtTrack("name", {
13
- * os: "MacOS",
14
- * device: "Cloud agent",
15
- * customTags: "Cloud, DarkTheme, Auth",
16
- * diffTollerancePercent: 1.23,
17
- * ignoreAreas: [
18
- * {x: 1, y: 2, width: 100, height: 200}
19
- * ],
20
- * retryLimit: 5,
21
- * keepScreenshot: false,
22
- * })
23
- */
24
- vrtTrack(name: string, options?: Partial<Loggable & Timeoutable & ScreenshotOptions & TrackOptions & {
25
- keepScreenshot?: boolean;
26
- }>, errorCallback?: (err: string) => boolean): Chainable<null>;
27
- vrtTrackBuffer(name: string, imageBuffer: Buffer, options?: Partial<Loggable & Timeoutable & ScreenshotOptions & TrackOptions>): Chainable<null>;
28
- vrtTrackBase64(name: string, imageBase64: string, options?: Partial<Loggable & Timeoutable & ScreenshotOptions & TrackOptions>): Chainable<null>;
29
- vrtStart(): null;
30
- vrtStop(): null;
31
- }
32
- interface IgnoreArea {
33
- x: number;
34
- y: number;
35
- width: number;
36
- height: number;
37
- }
38
- interface TrackOptions {
39
- viewport?: string;
40
- os?: string;
41
- device?: string;
42
- customTags?: string;
43
- diffTollerancePercent?: number;
44
- ignoreAreas?: IgnoreArea[];
45
- retryLimit?: number;
46
- }
47
- }
1
+ export { addVrtStartCommand, addVrtStopCommand, addVrtTrackCommand, addVrtTrackBufferCommand, addVrtTrackBase64Command, addVrtCommands, } from "./commands";
2
+ export { addVisualRegressionTrackerPlugin } from "./plugin";
package/dist/index.js CHANGED
@@ -1 +1,12 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addVisualRegressionTrackerPlugin = exports.addVrtCommands = exports.addVrtTrackBase64Command = exports.addVrtTrackBufferCommand = exports.addVrtTrackCommand = exports.addVrtStopCommand = exports.addVrtStartCommand = void 0;
4
+ var commands_1 = require("./commands");
5
+ Object.defineProperty(exports, "addVrtStartCommand", { enumerable: true, get: function () { return commands_1.addVrtStartCommand; } });
6
+ Object.defineProperty(exports, "addVrtStopCommand", { enumerable: true, get: function () { return commands_1.addVrtStopCommand; } });
7
+ Object.defineProperty(exports, "addVrtTrackCommand", { enumerable: true, get: function () { return commands_1.addVrtTrackCommand; } });
8
+ Object.defineProperty(exports, "addVrtTrackBufferCommand", { enumerable: true, get: function () { return commands_1.addVrtTrackBufferCommand; } });
9
+ Object.defineProperty(exports, "addVrtTrackBase64Command", { enumerable: true, get: function () { return commands_1.addVrtTrackBase64Command; } });
10
+ Object.defineProperty(exports, "addVrtCommands", { enumerable: true, get: function () { return commands_1.addVrtCommands; } });
11
+ var plugin_1 = require("./plugin");
12
+ Object.defineProperty(exports, "addVisualRegressionTrackerPlugin", { enumerable: true, get: function () { return plugin_1.addVisualRegressionTrackerPlugin; } });
package/dist/plugin.d.ts CHANGED
@@ -1 +1,8 @@
1
- export function addVisualRegressionTrackerPlugin(on: any, config: any): void;
1
+ /// <reference types="cypress" />
2
+ /**
3
+ * Register task event handlers for Cypress.
4
+ * @param on
5
+ * @param config
6
+ * @see https://docs.cypress.io/api/commands/task
7
+ */
8
+ export declare function addVisualRegressionTrackerPlugin(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions): void;
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) {
@@ -19,136 +8,63 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
20
9
  });
21
10
  };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
11
  Object.defineProperty(exports, "__esModule", { value: true });
50
12
  exports.addVisualRegressionTrackerPlugin = void 0;
51
- var fs_1 = require("fs");
52
- var sdk_js_1 = require("@visual-regression-tracker/sdk-js");
13
+ const fs_1 = require("fs");
14
+ const sdk_js_1 = require("@visual-regression-tracker/sdk-js");
15
+ const utils_1 = require("./utils");
16
+ /**
17
+ * Register task event handlers for Cypress.
18
+ * @param on
19
+ * @param config
20
+ * @see https://docs.cypress.io/api/commands/task
21
+ */
53
22
  function addVisualRegressionTrackerPlugin(on, config) {
54
23
  var _a;
55
- var _this = this;
56
- var _b;
57
- var vrtConfig = (_b = config === null || config === void 0 ? void 0 : config.env) === null || _b === void 0 ? void 0 : _b.visualRegressionTracker;
58
- var vrt = new sdk_js_1.VisualRegressionTracker(vrtConfig);
59
- on("task", (_a = {},
60
- _a["VRT_START"] = function (props) { return __awaiter(_this, void 0, void 0, function () {
61
- var err_1;
62
- var _a;
63
- return __generator(this, function (_b) {
64
- switch (_b.label) {
65
- case 0:
66
- _b.trys.push([0, 3, , 4]);
67
- if (!!vrt["isStarted"]()) return [3 /*break*/, 2];
68
- return [4 /*yield*/, vrt.start()];
69
- case 1:
70
- _b.sent();
71
- _b.label = 2;
72
- case 2: return [3 /*break*/, 4];
73
- case 3:
74
- err_1 = _b.sent();
75
- return [2 /*return*/, (_a = err_1.message) !== null && _a !== void 0 ? _a : err_1];
76
- case 4: return [2 /*return*/, null];
77
- }
78
- });
79
- }); },
80
- _a["VRT_STOP"] = function (props) { return __awaiter(_this, void 0, void 0, function () {
81
- var err_2;
82
- var _a;
83
- return __generator(this, function (_b) {
84
- switch (_b.label) {
85
- case 0:
86
- _b.trys.push([0, 3, , 4]);
87
- if (!vrt["isStarted"]()) return [3 /*break*/, 2];
88
- return [4 /*yield*/, vrt.stop()];
89
- case 1:
90
- _b.sent();
91
- _b.label = 2;
92
- case 2: return [3 /*break*/, 4];
93
- case 3:
94
- err_2 = _b.sent();
95
- return [2 /*return*/, (_a = err_2.message) !== null && _a !== void 0 ? _a : err_2];
96
- case 4: return [2 /*return*/, null];
24
+ const vrtConfig = (_a = config === null || config === void 0 ? void 0 : config.env) === null || _a === void 0 ? void 0 : _a.visualRegressionTracker;
25
+ const vrt = new sdk_js_1.VisualRegressionTracker(vrtConfig);
26
+ on("task", {
27
+ // Start visual regression tracking unless it has already been started
28
+ [utils_1.VRT_TASK_START]: (props) => __awaiter(this, void 0, void 0, function* () {
29
+ var _b;
30
+ try {
31
+ if (!vrt[utils_1.VRT_IS_STARTED]()) {
32
+ yield vrt.start();
97
33
  }
98
- });
99
- }); },
100
- _a["VRT_TRACK_IMAGE_MULTIPART"] = function (props) { return __awaiter(_this, void 0, void 0, function () {
101
- var data, result;
102
- return __generator(this, function (_a) {
103
- switch (_a.label) {
104
- case 0:
105
- data = (0, sdk_js_1.multipartDtoToFormData)(__assign(__assign({}, props), { buildId: vrt.buildId, projectId: vrt.projectId, branchName: vrt.config.branchName }));
106
- return [4 /*yield*/, vrt["submitTestRunMultipart"](data)];
107
- case 1:
108
- result = _a.sent();
109
- if (!props.keepScreenshot) {
110
- (0, fs_1.unlinkSync)(props.imagePath);
111
- }
112
- return [2 /*return*/, result];
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);
34
+ }
35
+ catch (err) {
36
+ return (_b = err.message) !== null && _b !== void 0 ? _b : err;
37
+ }
38
+ return null;
39
+ }),
40
+ // Stop visual regression tracking if it was started
41
+ [utils_1.VRT_TASK_STOP]: (props) => __awaiter(this, void 0, void 0, function* () {
42
+ var _c;
43
+ try {
44
+ if (vrt[utils_1.VRT_IS_STARTED]()) {
45
+ yield vrt.stop();
145
46
  }
146
- catch (err) {
147
- return [2 /*return*/, (_a = err.message) !== null && _a !== void 0 ? _a : err];
47
+ }
48
+ catch (err) {
49
+ return (_c = err.message) !== null && _c !== void 0 ? _c : err;
50
+ }
51
+ return null;
52
+ }),
53
+ // Track the given test case and optionally clean up the screenshot
54
+ [utils_1.VRT_TASK_TRACK]: (props) => __awaiter(this, void 0, void 0, function* () {
55
+ var _d;
56
+ try {
57
+ return yield vrt.track(props, props === null || props === void 0 ? void 0 : props.retryLimit);
58
+ }
59
+ catch (err) {
60
+ return (_d = err.message) !== null && _d !== void 0 ? _d : err;
61
+ }
62
+ finally {
63
+ if (!props.keepScreenshot && props.imagePath) {
64
+ (0, fs_1.unlinkSync)(props.imagePath);
148
65
  }
149
- return [2 /*return*/, null];
150
- });
151
- }); },
152
- _a));
66
+ }
67
+ }),
68
+ });
153
69
  }
154
70
  exports.addVisualRegressionTrackerPlugin = addVisualRegressionTrackerPlugin;
@@ -0,0 +1,47 @@
1
+ /// <reference types="cypress" />
2
+ /// <reference types="node" />
3
+ declare namespace Cypress {
4
+ interface Chainable {
5
+ /**
6
+ * Validate image against baseline
7
+ * @param name Image identifier.
8
+ * @param options An object that contains one or more additional properties.
9
+ *
10
+ * @example
11
+ * cy.vrtTrack("name")
12
+ * cy.get("#id").vrtTrack("name", {
13
+ * os: "MacOS",
14
+ * device: "Cloud agent",
15
+ * customTags: "Cloud, DarkTheme, Auth",
16
+ * diffTollerancePercent: 1.23,
17
+ * ignoreAreas: [
18
+ * {x: 1, y: 2, width: 100, height: 200}
19
+ * ],
20
+ * retryLimit: 5,
21
+ * keepScreenshot: false,
22
+ * })
23
+ */
24
+ vrtTrack(name: string, options?: Partial<Loggable & Timeoutable & ScreenshotOptions & TrackOptions & {
25
+ keepScreenshot?: boolean;
26
+ }>, errorCallback?: (err: string) => boolean): Chainable<null>;
27
+ vrtTrackBuffer(name: string, imageBuffer: Buffer, options?: Partial<Loggable & Timeoutable & ScreenshotOptions & TrackOptions>): Chainable<null>;
28
+ vrtTrackBase64(name: string, imageBase64: string, options?: Partial<Loggable & Timeoutable & ScreenshotOptions & TrackOptions>): Chainable<null>;
29
+ vrtStart(): null;
30
+ vrtStop(): null;
31
+ }
32
+ interface IgnoreArea {
33
+ x: number;
34
+ y: number;
35
+ width: number;
36
+ height: number;
37
+ }
38
+ interface TrackOptions {
39
+ viewport?: string;
40
+ os?: string;
41
+ device?: string;
42
+ customTags?: string;
43
+ diffTollerancePercent?: number;
44
+ ignoreAreas?: IgnoreArea[];
45
+ retryLimit?: number;
46
+ }
47
+ }
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ /* global Cypress, cy */
3
+ //export { }
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,15 @@
1
1
  /// <reference types="cypress" />
2
2
  /// <reference types="node" />
3
3
  import { TestRunResponse } from "@visual-regression-tracker/sdk-js";
4
+ export declare const VRT_TASK_START = "VRT_START";
5
+ export declare const VRT_TASK_STOP = "VRT_STOP";
6
+ export declare const VRT_TASK_TRACK = "VRT_TRACK";
7
+ export declare const VRT_COMMAND_START = "vrtStart";
8
+ export declare const VRT_COMMAND_STOP = "vrtStop";
9
+ export declare const VRT_COMMAND_TRACK = "vrtTrack";
10
+ export declare const VRT_COMMAND_TRACK_BUFFER = "vrtTrackBuffer";
11
+ export declare const VRT_COMMAND_TRACK_BASE64 = "vrtTrackBase64";
12
+ export declare const VRT_IS_STARTED = "isStarted";
4
13
  export declare const log: (message: string) => Cypress.Log;
5
14
  export declare const handleError: (err: unknown) => void;
6
15
  export declare const toTestRunDto: ({ name, pixelRatio, options, }: {
@@ -17,10 +26,9 @@ export declare const toTestRunDto: ({ name, pixelRatio, options, }: {
17
26
  diffTollerancePercent: any;
18
27
  ignoreAreas: any;
19
28
  keepScreenshot: any;
29
+ retryLimit: any;
20
30
  };
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>;
23
- export declare const shouldStopRetry: (result: TestRunResponse) => boolean;
31
+ export declare const checkResult: (result: TestRunResponse | string, errorCallback?: ((err: string) => boolean) | undefined) => void;
24
32
  export declare const trackImage: (subject: any, name: string, options: any) => Cypress.Chainable<TestRunResponse>;
25
33
  export declare const trackBuffer: (name: string, imageBuffer: Buffer, options: any) => Cypress.Chainable<TestRunResponse>;
26
34
  export declare const trackBase64: (name: string, imageBase64: string, options: any) => Cypress.Chainable<TestRunResponse>;
package/dist/utils.js CHANGED
@@ -1,97 +1,83 @@
1
1
  "use strict";
2
2
  /* global Cypress, cy */
3
- var __assign = (this && this.__assign) || function () {
4
- __assign = Object.assign || function(t) {
5
- for (var s, i = 1, n = arguments.length; i < n; i++) {
6
- s = arguments[i];
7
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
8
- t[p] = s[p];
9
- }
10
- return t;
11
- };
12
- return __assign.apply(this, arguments);
13
- };
14
3
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.trackBase64 = exports.trackBuffer = exports.trackImage = exports.shouldStopRetry = exports.checkResult = exports.trackWithRetry = exports.toTestRunDto = exports.handleError = exports.log = void 0;
16
- var sdk_js_1 = require("@visual-regression-tracker/sdk-js");
17
- var log = function (message) {
18
- return Cypress.log({
19
- name: "Visual Regression Tracker",
20
- displayName: "VRT",
21
- message: message,
22
- });
23
- };
4
+ exports.trackBase64 = exports.trackBuffer = exports.trackImage = exports.checkResult = exports.toTestRunDto = exports.handleError = exports.log = exports.VRT_IS_STARTED = exports.VRT_COMMAND_TRACK_BASE64 = exports.VRT_COMMAND_TRACK_BUFFER = exports.VRT_COMMAND_TRACK = exports.VRT_COMMAND_STOP = exports.VRT_COMMAND_START = exports.VRT_TASK_TRACK = exports.VRT_TASK_STOP = exports.VRT_TASK_START = void 0;
5
+ // Task names
6
+ exports.VRT_TASK_START = "VRT_START";
7
+ exports.VRT_TASK_STOP = "VRT_STOP";
8
+ exports.VRT_TASK_TRACK = "VRT_TRACK";
9
+ // Command names
10
+ exports.VRT_COMMAND_START = "vrtStart";
11
+ exports.VRT_COMMAND_STOP = "vrtStop";
12
+ exports.VRT_COMMAND_TRACK = "vrtTrack";
13
+ exports.VRT_COMMAND_TRACK_BUFFER = "vrtTrackBuffer";
14
+ exports.VRT_COMMAND_TRACK_BASE64 = "vrtTrackBase64";
15
+ // Private method name in sdk-js, FIXME: public?
16
+ exports.VRT_IS_STARTED = "isStarted";
17
+ const log = (message) => Cypress.log({
18
+ name: "Visual Regression Tracker",
19
+ displayName: "VRT",
20
+ message,
21
+ });
24
22
  exports.log = log;
25
- var handleError = function (err) {
23
+ const handleError = (err) => {
26
24
  if (err) {
27
25
  throw new Error(err);
28
26
  }
29
27
  };
30
28
  exports.handleError = handleError;
31
- var toTestRunDto = function (_a) {
32
- var _b;
33
- var name = _a.name, _c = _a.pixelRatio, pixelRatio = _c === void 0 ? 1 : _c, options = _a.options;
29
+ const toTestRunDto = ({ name, pixelRatio = 1, options, }) => {
30
+ var _a;
34
31
  return ({
35
- name: name,
32
+ name,
36
33
  browser: Cypress.browser.name,
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),
34
+ viewport: (_a = options === null || options === void 0 ? void 0 : options.viewport) !== null && _a !== void 0 ? _a : `${Cypress.config("viewportWidth") * pixelRatio}x${Cypress.config("viewportHeight") * pixelRatio}`,
38
35
  os: options === null || options === void 0 ? void 0 : options.os,
39
36
  device: options === null || options === void 0 ? void 0 : options.device,
40
37
  customTags: options === null || options === void 0 ? void 0 : options.customTags,
41
38
  diffTollerancePercent: options === null || options === void 0 ? void 0 : options.diffTollerancePercent,
42
39
  ignoreAreas: options === null || options === void 0 ? void 0 : options.ignoreAreas,
40
+ // next two properties actually do not belong to TestRunDto and ideally should be removed from this object
43
41
  keepScreenshot: options === null || options === void 0 ? void 0 : options.keepScreenshot,
42
+ retryLimit: options === null || options === void 0 ? void 0 : options.retryLimit,
44
43
  });
45
44
  };
46
45
  exports.toTestRunDto = toTestRunDto;
47
- var trackWithRetry = function (trackFn, shouldStopFn, onStopFn, retryLimit) {
48
- if (retryLimit === void 0) { retryLimit = 2; }
49
- return trackFn().then(function (result) {
50
- if (retryLimit <= 0 || shouldStopFn(result)) {
51
- onStopFn(result);
52
- return;
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;
46
+ const checkResult = (result, errorCallback) => {
47
+ if (typeof result === "string") {
48
+ // . this is an error message
49
+ if (errorCallback) {
50
+ if (errorCallback(result)) {
51
+ return;
52
+ }
63
53
  }
54
+ (0, exports.handleError)(result);
64
55
  }
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
56
  };
71
- exports.shouldStopRetry = shouldStopRetry;
72
- var trackImage = function (subject, name, options) {
73
- var imagePath;
74
- var pixelRatio;
75
- var target = subject ? cy.wrap(subject) : cy;
57
+ exports.checkResult = checkResult;
58
+ const trackImage = (subject, name, options) => {
59
+ let imagePath;
60
+ let pixelRatio;
61
+ const target = subject ? cy.wrap(subject) : cy;
62
+ // cy.screenshot() return Type is always Chainable<null>
63
+ // https://github.com/cypress-io/cypress/issues/21277
76
64
  return target
77
- .screenshot(name, __assign(__assign({}, options), { onAfterScreenshot: function (el, props) {
65
+ .screenshot(name, Object.assign(Object.assign({}, options), { onAfterScreenshot: ($el, props) => {
78
66
  imagePath = props.path;
79
67
  pixelRatio = props.pixelRatio;
80
68
  return options === null || options === void 0 ? void 0 : options.onAfterScreenshot;
81
- } }))
82
- .then(function () { return (0, exports.log)("tracking ".concat(name)); })
83
- .then(function () {
84
- return cy.task("VRT_TRACK_IMAGE_MULTIPART", __assign(__assign({}, (0, exports.toTestRunDto)({ name: name, pixelRatio: pixelRatio, options: options })), { imagePath: imagePath }), { log: false });
85
- });
69
+ } })) // @ts-ignore
70
+ .then(() => (0, exports.log)(`tracking ${name}`))
71
+ .then(() => cy.task(exports.VRT_TASK_TRACK, Object.assign(Object.assign({}, (0, exports.toTestRunDto)({ name, pixelRatio, options })), { imagePath }), { log: false }));
86
72
  };
87
73
  exports.trackImage = trackImage;
88
- var trackBuffer = function (name, imageBuffer, options) {
89
- (0, exports.log)("tracking ".concat(name));
90
- return cy.task("VRT_TRACK_BUFFER_MULTIPART", __assign(__assign({}, (0, exports.toTestRunDto)({ name: name, options: options })), { imageBuffer: imageBuffer }), { log: false });
74
+ const trackBuffer = (name, imageBuffer, options) => {
75
+ (0, exports.log)(`tracking ${name}`);
76
+ return cy.task(exports.VRT_TASK_TRACK, Object.assign(Object.assign({}, (0, exports.toTestRunDto)({ name, options })), { imageBuffer }), { log: false });
91
77
  };
92
78
  exports.trackBuffer = trackBuffer;
93
- var trackBase64 = function (name, imageBase64, options) {
94
- (0, exports.log)("tracking ".concat(name));
95
- return cy.task("VRT_TRACK_IMAGE_BASE64", __assign(__assign({}, (0, exports.toTestRunDto)({ name: name, options: options })), { imageBase64: imageBase64 }), { log: false });
79
+ const trackBase64 = (name, imageBase64, options) => {
80
+ (0, exports.log)(`tracking ${name}`);
81
+ return cy.task(exports.VRT_TASK_TRACK, Object.assign(Object.assign({}, (0, exports.toTestRunDto)({ name, options })), { imageBase64 }), { log: false });
96
82
  };
97
83
  exports.trackBase64 = trackBase64;
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@visual-regression-tracker/agent-cypress",
3
- "version": "5.5.0",
4
- "description": "Visual Regression Tracker integration plugin",
3
+ "version": "5.7.0",
4
+ "description": "Visual Regression Tracker integration plugin for Cypress",
5
5
  "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
6
+ "types": "dist/",
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
  },
@@ -19,22 +18,28 @@
19
18
  "visual-regression-tracker"
20
19
  ],
21
20
  "author": "Pavel Strunkin <pashidlos@gmail.com>",
22
- "license": "MIT",
21
+ "license": "Apache-2.0",
23
22
  "bugs": {
24
23
  "url": "https://github.com/Visual-Regression-Tracker/agent-cypress/issues"
25
24
  },
26
25
  "homepage": "https://github.com/Visual-Regression-Tracker/agent-cypress#readme",
26
+ "engines": {
27
+ "node": ">=16.16.0"
28
+ },
27
29
  "dependencies": {
28
- "@visual-regression-tracker/sdk-js": "5.3.0"
30
+ "@visual-regression-tracker/sdk-js": "5.7.0"
29
31
  },
30
32
  "devDependencies": {
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"
33
+ "@types/jest": "^29.5.3",
34
+ "@types/node": "^16.18.38",
35
+ "cypress": "^12.17.3",
36
+ "jest": "^29.6.1",
37
+ "semantic-release": "^21.0.7",
38
+ "ts-jest": "^29.1.1",
39
+ "typescript": "^5.1.6"
40
+ },
41
+ "peerDependencies": {
42
+ "cypress": ">=12.17.1"
38
43
  },
39
44
  "publishConfig": {
40
45
  "access": "public"