@visual-regression-tracker/agent-cypress 5.7.1 → 5.9.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/README.md CHANGED
@@ -1,194 +1,175 @@
1
- # Native integration for [Cypress](https://www.cypress.io/) with [Visual Regression Tracker](https://github.com/Visual-Regression-Tracker/Visual-Regression-Tracker)
1
+ # Cypress agent for [Visual Regression Tracker](https://github.com/Visual-Regression-Tracker/Visual-Regression-Tracker)
2
2
 
3
- [![Codacy Badge](https://app.codacy.com/project/badge/Grade/4ebb8d37b8f943548e992a7d063ac998)](https://www.codacy.com/gh/Visual-Regression-Tracker/agent-cypress?utm_source=github.com&utm_medium=referral&utm_content=Visual-Regression-Tracker/agent-cypress&utm_campaign=Badge_Grade)
3
+ [![npm](https://img.shields.io/npm/v/@visual-regression-tracker/agent-cypress)](https://www.npmjs.com/package/@visual-regression-tracker/agent-cypress)
4
4
 
5
- Npm: https://www.npmjs.com/package/@visual-regression-tracker/agent-cypress
5
+ Adds `cy.vrtStart()`, `cy.vrtTrack()` and `cy.vrtStop()` to [Cypress](https://www.cypress.io) tests. The agent is built on [sdk-js](https://github.com/Visual-Regression-Tracker/sdk-js).
6
6
 
7
- ## Installation
7
+ ## Requirements
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).
9
+ - Cypress 12.17.1 or later
10
+ - Node.js 18 or later
11
+ - Visual Regression Tracker server 5.0.8 or later; 6 is recommended
10
12
 
11
- ### Add package
13
+ ## Install
12
14
 
13
- `npm install @visual-regression-tracker/agent-cypress`
14
-
15
- ### Add commands
16
-
17
- `<rootDir>/cypress/support/e2e.js` or `<rootDir>/cypress/support/component.js`
18
-
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:
30
-
31
- ```js
32
- import {
33
- addVrtTrackCommand,
34
- addVrtStartCommand,
35
- addVrtStopCommand,
36
- addVrtTrackBufferCommand,
37
- addVrtTrackBase64Command,
38
- } from "@visual-regression-tracker/agent-cypress";
39
-
40
- addVrtStartCommand();
41
- addVrtStopCommand();
42
- addVrtTrackCommand();
43
- addVrtTrackBufferCommand();
44
- addVrtTrackBase64Command();
15
+ ```sh
16
+ npm install --save-dev @visual-regression-tracker/agent-cypress
45
17
  ```
46
18
 
47
- ### Add plugin
48
-
49
- `<rootDir>/cypress.config.js`
19
+ Register the plugin in `cypress.config.js` (under `component` for component tests):
50
20
 
51
21
  ```js
52
- import { defineConfig } from 'cypress';
22
+ import { defineConfig } from "cypress";
53
23
  import { addVisualRegressionTrackerPlugin } from "@visual-regression-tracker/agent-cypress";
54
24
 
55
25
  export default defineConfig({
56
- // e2e or component, depending of testing style
57
26
  e2e: {
58
- setupNodeEvents (on, config) => {
27
+ setupNodeEvents(on, config) {
59
28
  addVisualRegressionTrackerPlugin(on, config);
60
- }
61
- }
29
+ },
30
+ },
62
31
  });
63
32
  ```
64
33
 
65
- ### Configuration
34
+ Add the commands in `cypress/support/e2e.js` (or `component.js`):
35
+
36
+ ```js
37
+ import { addVrtCommands } from "@visual-regression-tracker/agent-cypress";
38
+
39
+ addVrtCommands();
40
+ ```
66
41
 
67
- #### Update Cypress config
42
+ To add only some of them, use `addVrtStartCommand`, `addVrtStopCommand`, `addVrtTrackCommand`, `addVrtTrackBufferCommand` and `addVrtTrackBase64Command`.
68
43
 
69
- `<rootDir>/cypress.config.js`
44
+ ## Configuration
45
+
46
+ | Option | Environment variable | Required | Default | Description |
47
+ | --- | --- | --- | --- | --- |
48
+ | `apiUrl` | `VRT_APIURL` | yes | | URL of the server API, e.g. `http://localhost:4200` |
49
+ | `apiKey` | `VRT_APIKEY` | yes | | API key of a user with access to the project |
50
+ | `project` | `VRT_PROJECT` | yes | | Project name or ID |
51
+ | `branchName` | `VRT_BRANCHNAME` | yes | | Current git branch |
52
+ | `sourceBranch` | `VRT_SOURCEBRANCH` | no | project's main branch | Branch to take baselines from while `branchName` has none of its own |
53
+ | `ciBuildId` | `VRT_CIBUILDID` | no | | ID of one CI build; machines with the same ID share a build |
54
+ | `enableSoftAssert` | `VRT_ENABLESOFTASSERT` | no | `false` | Log failed comparisons instead of failing the test |
55
+
56
+ Set the options under `env.visualRegressionTracker` in the Cypress config:
70
57
 
71
58
  ```js
72
59
  export default defineConfig({
73
-
74
60
  env: {
75
- "visualRegressionTracker": {
76
- // URL where backend is running
77
- // Required
78
- "apiUrl": "http://localhost:4200",
79
-
80
- // Project name or ID
81
- // Required
82
- "project": "Default project",
83
-
84
- // User apiKey
85
- // Required
86
- "apiKey": "tXZVHX0EA4YQM1MGDD",
87
-
88
- // Current git branch
89
- // Required
90
- "branchName": "develop",
91
-
92
- // Branch with baseline
93
- // Optional - when not set, main branch from project settings is used
94
- "baselineBranchName": "release",
95
-
96
- // Log errors instead of throwing exceptions
97
- // Optional - default false
98
- "enableSoftAssert": true,
99
-
100
- // Unique ID related to one CI build
101
- // Optional - default null
102
- "ciBuildId": "SOME_UNIQUE_ID",
103
- }
104
- }
61
+ visualRegressionTracker: {
62
+ apiUrl: "http://localhost:4200",
63
+ apiKey: "tXZVHX0EA4YQM1MGDD",
64
+ project: "Default project",
65
+ branchName: "develop",
66
+ },
67
+ },
105
68
  });
106
69
  ```
107
70
 
108
- #### Or, as JSON config file `vrt.json`
109
-
110
- _Used only if not explicit config provided_
111
- _Is overriden if ENV variables are present_
71
+ If `visualRegressionTracker` is not set, the options are read from `vrt.json` in the working directory, with the same keys:
112
72
 
113
73
  ```json
114
74
  {
115
75
  "apiUrl": "http://localhost:4200",
116
- "project": "Default project",
117
76
  "apiKey": "tXZVHX0EA4YQM1MGDD",
118
- "ciBuildId": "commit_sha",
77
+ "project": "Default project",
119
78
  "branchName": "develop",
79
+ "sourceBranch": "release",
80
+ "ciBuildId": "commit_sha",
120
81
  "enableSoftAssert": false
121
82
  }
122
83
  ```
123
84
 
124
- #### Or, as environment variables
85
+ Environment variables override `vrt.json` key by key. When `visualRegressionTracker` is set, only `VRT_SOURCEBRANCH` is read from the environment.
125
86
 
126
- _Used only if not explicit config provided_
127
-
128
- ```
129
- VRT_APIURL="http://localhost:4200"
130
- VRT_PROJECT="Default project"
131
- VRT_APIKEY="tXZVHX0EA4YQM1MGDD"
132
- VRT_CIBUILDID="commit_sha"
133
- VRT_BRANCHNAME="develop"
134
- VRT_BASELINEBRANCHNAME="release"
135
- VRT_ENABLESOFTASSERT=true
136
- ```
87
+ `baselineBranchName` (`VRT_BASELINEBRANCHNAME`) is a deprecated alias of `sourceBranch`. It still works and logs a warning once.
137
88
 
138
89
  ## Usage
139
90
 
140
- ### Setup
141
-
142
91
  ```js
143
- cy.vrtStart();
144
- ```
92
+ before(() => cy.vrtStart());
93
+ after(() => cy.vrtStop());
145
94
 
146
- ### Assert
147
-
148
- ```js
149
- cy.vrtTrack("Whole page with default params");
95
+ it("home page", () => {
96
+ cy.visit("/");
150
97
 
151
- cy.get("#navbar").vrtTrack("Separate element with default params");
98
+ cy.vrtTrack("Home page");
152
99
 
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",
100
+ cy.get("#navbar").vrtTrack("Navbar", {
101
+ os: "linux",
102
+ device: "desktop",
103
+ customTags: "smoke,dark",
104
+ comment: "Logged out",
160
105
  diffTollerancePercent: 1,
161
106
  ignoreAreas: [{ x: 1, y: 2, width: 100, height: 200 }],
162
107
  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
- );
108
+ keepScreenshot: false,
109
+ });
110
+ });
170
111
  ```
171
112
 
172
- ##### options (optional)
113
+ `cy.vrtTrack(name, options, errorCallback)` takes a screenshot of the page, or of the element it is chained on, and uploads it as multipart. Every option is optional:
114
+
115
+ | Option | Description |
116
+ | --- | --- |
117
+ | `os`, `device`, `customTags` | Tell baselines of the same name apart |
118
+ | `viewport` | Defaults to `viewportWidth`x`viewportHeight` times the pixel ratio |
119
+ | `diffTollerancePercent` | Allowed difference, in percent of all pixels (the spelling is the API's) |
120
+ | `comment` | Shown with the test run |
121
+ | `ignoreAreas` | `[{ x, y, width, height }]` in pixels, left out of the comparison |
122
+ | `retryLimit` | Retries while the result is `unresolved`, default 2 |
123
+ | `keepScreenshot` | Keep the local screenshot file, default `false` |
124
+ | any [`cy.screenshot()` option](https://docs.cypress.io/api/commands/screenshot#Arguments) | Passed to the screenshot |
173
125
 
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)
126
+ The browser is taken from `Cypress.browser.name`.
175
127
 
176
- Viewport is taken from `Cypress.config()`, if option is not set
128
+ `cy.vrtTrackBuffer(name, buffer, options)` and `cy.vrtTrackBase64(name, base64, options)` track an image you already have.
177
129
 
178
- Browser is taken from `Cypress.browser.name`
130
+ ## Results and statuses
179
131
 
180
- ##### errorCallbak (optional)
132
+ | Status | Outcome |
133
+ | --- | --- |
134
+ | `new` | No baseline yet: fails the test, or logs with `enableSoftAssert` |
135
+ | `unresolved` | Differs from the baseline: fails the test, or logs with `enableSoftAssert` |
136
+ | `ok`, `approved`, `autoApproved` | Passes |
137
+ | `failed` | A reviewer rejected it: passes with a warning |
138
+ | anything else | Passes with a warning |
181
139
 
182
- Allows you to define a callback that receives the error for custom side-effects.
140
+ Logs and warnings appear in the terminal that runs Cypress, not in the browser.
183
141
 
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.
142
+ ## Errors
185
143
 
186
- ### Teadown
144
+ A failed comparison or request fails the test with the server's message. Use `errorCallback` to handle it for one screenshot:
187
145
 
188
146
  ```js
189
- cy.vrtStop();
147
+ cy.vrtTrack("Home page", {}, (err) => {
148
+ cy.log(err);
149
+ return true; // true: do not fail the test
150
+ });
190
151
  ```
191
152
 
153
+ Request errors name the HTTP status and add a hint for common causes, such as a wrong `apiKey` (401) or an image over the server's limits (413, 422). See [sdk-js](https://github.com/Visual-Regression-Tracker/sdk-js#errors).
154
+
192
155
  ## Examples
193
156
 
194
- https://github.com/Visual-Regression-Tracker/examples-js
157
+ [examples-js](https://github.com/Visual-Regression-Tracker/examples-js)
158
+
159
+ ## Releasing
160
+
161
+ Every push to `master` runs [semantic-release](https://semantic-release.gitbook.io). It reads the [Conventional Commits](https://www.conventionalcommits.org) since the last `v*` tag:
162
+
163
+ | Commit | Release |
164
+ | --- | --- |
165
+ | `fix:` | patch |
166
+ | `feat:` | minor |
167
+ | `feat!:` or a `BREAKING CHANGE:` footer | major |
168
+ | `chore:`, `ci:`, `docs:`, `test:` | none |
169
+
170
+ It then publishes to npm through trusted publishing with provenance, tags `vX.Y.Z`, and writes the GitHub release.
171
+ The `version` field in `package.json` is a placeholder. The released version lives in the tags and on npm.
172
+
173
+ ## License
174
+
175
+ [Apache-2.0](LICENSE)
package/dist/plugin.js CHANGED
@@ -23,7 +23,10 @@ const utils_1 = require("./utils");
23
23
  function addVisualRegressionTrackerPlugin(on, config) {
24
24
  var _a;
25
25
  const vrtConfig = (_a = config === null || config === void 0 ? void 0 : config.env) === null || _a === void 0 ? void 0 : _a.visualRegressionTracker;
26
- const vrt = new sdk_js_1.VisualRegressionTracker(vrtConfig);
26
+ // sdk-js skips VRT_* variables when given an explicit config
27
+ const vrt = new sdk_js_1.VisualRegressionTracker(vrtConfig && Object.assign(Object.assign({}, vrtConfig), { sourceBranch: vrtConfig.sourceBranch ||
28
+ vrtConfig.baselineBranchName ||
29
+ process.env.VRT_SOURCEBRANCH }));
27
30
  on("task", {
28
31
  // Start visual regression tracking unless it has already been started
29
32
  [utils_1.VRT_TASK_START]: (props) => __awaiter(this, void 0, void 0, function* () {
package/dist/types.d.ts CHANGED
@@ -13,6 +13,7 @@ declare namespace Cypress {
13
13
  * os: "MacOS",
14
14
  * device: "Cloud agent",
15
15
  * customTags: "Cloud, DarkTheme, Auth",
16
+ * comment: "Logged out",
16
17
  * diffTollerancePercent: 1.23,
17
18
  * ignoreAreas: [
18
19
  * {x: 1, y: 2, width: 100, height: 200}
@@ -40,6 +41,7 @@ declare namespace Cypress {
40
41
  os?: string;
41
42
  device?: string;
42
43
  customTags?: string;
44
+ comment?: string;
43
45
  diffTollerancePercent?: number;
44
46
  ignoreAreas?: IgnoreArea[];
45
47
  retryLimit?: number;
package/dist/utils.d.ts CHANGED
@@ -23,6 +23,7 @@ export declare const toTestRunDto: ({ name, pixelRatio, options, }: {
23
23
  os: any;
24
24
  device: any;
25
25
  customTags: any;
26
+ comment: any;
26
27
  diffTollerancePercent: any;
27
28
  ignoreAreas: any;
28
29
  keepScreenshot: any;
package/dist/utils.js CHANGED
@@ -37,6 +37,7 @@ const toTestRunDto = ({ name, pixelRatio = 1, options, }) => {
37
37
  os: options === null || options === void 0 ? void 0 : options.os,
38
38
  device: options === null || options === void 0 ? void 0 : options.device,
39
39
  customTags: options === null || options === void 0 ? void 0 : options.customTags,
40
+ comment: options === null || options === void 0 ? void 0 : options.comment,
40
41
  diffTollerancePercent: options === null || options === void 0 ? void 0 : options.diffTollerancePercent,
41
42
  ignoreAreas: options === null || options === void 0 ? void 0 : options.ignoreAreas,
42
43
  // next two properties actually do not belong to TestRunDto and ideally should be removed from this object
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "@visual-regression-tracker/agent-cypress",
3
- "version": "5.7.1",
3
+ "version": "5.9.0",
4
4
  "description": "Visual Regression Tracker integration plugin for Cypress",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/",
7
+ "files": [
8
+ "dist"
9
+ ],
7
10
  "scripts": {
8
11
  "build": "tsc",
9
12
  "test": "jest",
@@ -28,15 +31,14 @@
28
31
  "node": ">=16.16.0"
29
32
  },
30
33
  "dependencies": {
31
- "@visual-regression-tracker/sdk-js": "5.7.2"
34
+ "@visual-regression-tracker/sdk-js": "^5.8.1"
32
35
  },
33
36
  "devDependencies": {
34
37
  "@jest/globals": "^30.5.2",
35
38
  "@types/jest": "^30.0.0",
36
39
  "@types/node": "^22.20.5",
37
- "cypress": "^16.2.0",
40
+ "cypress": "^16.2.1",
38
41
  "jest": "^30.5.2",
39
- "semantic-release": "^25.0.9",
40
42
  "ts-jest": "^29.4.15",
41
43
  "typescript": "^6.0.3"
42
44
  },
@@ -45,5 +47,12 @@
45
47
  },
46
48
  "publishConfig": {
47
49
  "access": "public"
50
+ },
51
+ "overrides": {
52
+ "glob": "^14.0.2",
53
+ "minimatch": "^11.0.1"
54
+ },
55
+ "release": {
56
+ "preset": "conventionalcommits"
48
57
  }
49
58
  }
@@ -1,42 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: npm
4
- directory: "/"
5
- schedule:
6
- interval: daily
7
- open-pull-requests-limit: 2
8
- ignore:
9
- - dependency-name: "@types/node"
10
- versions:
11
- - 14.14.22
12
- - 14.14.24
13
- - 14.14.25
14
- - 14.14.26
15
- - 14.14.28
16
- - 14.14.30
17
- - 14.14.31
18
- - 14.14.33
19
- - 14.14.34
20
- - 14.14.35
21
- - 14.14.36
22
- - 14.14.37
23
- - 14.14.39
24
- - 14.14.41
25
- - 15.0.0
26
- - dependency-name: ssri
27
- versions:
28
- - 6.0.2
29
- - dependency-name: y18n
30
- versions:
31
- - 4.0.1
32
- - 4.0.2
33
- - 4.0.3
34
- - dependency-name: semantic-release
35
- versions:
36
- - 17.4.2
37
- - dependency-name: cypress
38
- versions:
39
- - 6.3.0
40
- - 6.4.0
41
- - 6.5.0
42
- - 6.6.0
@@ -1,26 +0,0 @@
1
- name: CI
2
-
3
- on:
4
- pull_request:
5
- branches: [master]
6
-
7
- jobs:
8
- build:
9
- runs-on: ubuntu-latest
10
-
11
- steps:
12
- - uses: actions/checkout@v5
13
-
14
- - name: Setup Node.js environment
15
- uses: actions/setup-node@v5
16
- with:
17
- node-version: 22
18
-
19
- - name: Install npm dependencies
20
- run: npm ci
21
-
22
- - name: Build
23
- run: npm run build
24
-
25
- - name: Unit tests
26
- run: npm test
@@ -1,37 +0,0 @@
1
- name: Release
2
- on:
3
- push:
4
- branches:
5
- - master
6
- jobs:
7
- release:
8
- name: Release
9
- runs-on: ubuntu-latest
10
- permissions:
11
- contents: write # to publish a GitHub release
12
- issues: write # to comment on released issues
13
- pull-requests: write # to comment on released pull requests
14
- id-token: write # to publish to npm with trusted publishing (OIDC) and provenance
15
-
16
- steps:
17
- - name: Checkout
18
- uses: actions/checkout@v5
19
- with:
20
- fetch-depth: 0
21
-
22
- - name: Setup Node.js environment
23
- uses: actions/setup-node@v5
24
- with:
25
- node-version: 22
26
-
27
- - name: Install dependencies
28
- run: npm ci
29
-
30
- - name: Build
31
- run: npm run build
32
-
33
- - name: Release
34
- env:
35
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
37
- run: npx semantic-release
package/cypress.config.ts DELETED
@@ -1,30 +0,0 @@
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
- });