Skip to content

Commit 03cfd1d

Browse files
committed
chore: merge branch 'main' into feat/deferred-failures-and-batch-review-ui
# Conflicts: # packages/cypress-plugin-visual-regression-diff/src/commands.ts
2 parents 08e38ae + a9c8e3e commit 03cfd1d

13 files changed

Lines changed: 227 additions & 23 deletions

File tree

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"packages/cypress-plugin-visual-regression-diff": "4.0.2"
2+
"packages/cypress-plugin-visual-regression-diff": "4.1.0"
33
}

examples/next/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"dev": "next dev",
55
"build": "next build",
66
"start": "next start",
7-
"cypress": "cypress open --env \"pluginVisualRegressionUpdateImages=true,pluginVisualRegressionImagesPath={spec_path}/__image_snapshots_local__\"",
7+
"cypress": "cypress open --env \"pluginVisualRegressionImagesPath={spec_path}/__image_snapshots_local__\"",
88
"cypress:ci": "cypress run --env \"pluginVisualRegressionUpdateImages=true\"",
99
"test:e2e": "start-server-and-test dev http://localhost:3000 \"pnpm cypress --e2e\"",
1010
"test:e2e:ci": "start-server-and-test dev http://localhost:3000 \"pnpm cypress:ci --e2e\"",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"build": "pnpm -r build",
77
"lint": "eslint '**/*.ts' --ignore-pattern '**/*.d.ts'",
8-
"lint:fix": "pnpm lint --fix",
8+
"fix": "pnpm lint --fix",
99
"lint:ci": "pnpm lint --max-warnings 0",
1010
"format": "pnpm -r format",
1111
"format:ci": "pnpm -r format:ci",

packages/cypress-plugin-visual-regression-diff/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [4.1.0](https://github.com/FRSOURCE/cypress-plugin-visual-regression-diff/compare/@frsource/cypress-plugin-visual-regression-diff-v4.0.2...@frsource/cypress-plugin-visual-regression-diff-v4.1.0) (2026-07-02)
4+
5+
6+
### Features
7+
8+
* migrate plugin options from Cypress.env() to Cypress.expose() in preparation for Cypress 16 ([#376](https://github.com/FRSOURCE/cypress-plugin-visual-regression-diff/issues/376)) ([2b71557](https://github.com/FRSOURCE/cypress-plugin-visual-regression-diff/commit/2b7155700bcddbbef92c5c42d0e5fe05beb3fa00)), closes [#375](https://github.com/FRSOURCE/cypress-plugin-visual-regression-diff/issues/375). For migration guide, go to this link: https://github.com/FRSOURCE/cypress-plugin-visual-regression-diff/blob/main/packages/cypress-plugin-visual-regression-diff/MIGRATION.md#40x---41x
9+
310
## [4.0.2](https://github.com/FRSOURCE/cypress-plugin-visual-regression-diff/compare/@frsource/cypress-plugin-visual-regression-diff-v4.0.1...@frsource/cypress-plugin-visual-regression-diff-v4.0.2) (2026-06-28)
411

512

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Migration Guide
2+
3+
## 4.0.x -> 4.1.x
4+
5+
### Migrating to Cypress 16 (`Cypress.expose` API)
6+
7+
Cypress 16 removes `Cypress.env()` in favor of the new `Cypress.expose()` API (introduced in Cypress 15.10.0).
8+
This plugin supports both APIs automatically based on the detected Cypress version:
9+
10+
- **Cypress ≥ 15.10** – reads plugin options via `Cypress.expose()` / `config.expose`
11+
- **Cypress < 15.10** – reads plugin options via `Cypress.env()` / `config.env` (legacy)
12+
13+
No code change is required inside your tests. You only need to update **how you supply plugin options**.
14+
15+
### What changed
16+
17+
| Location | Before (all Cypress versions) | After (Cypress ≥ 15.10) |
18+
| ------------------- | ----------------------------- | ------------------------------------------- |
19+
| CLI flag | `--env "key=value"` | `--expose "key=value"` |
20+
| `cypress.config.ts` | `env: { key: value }` | `expose: { key: value }` |
21+
| `cypress.env.json` | `{ "key": "value" }` | use `expose` in `cypress.config.ts` instead |
22+
23+
### Plugin option names
24+
25+
All option names stay the same — they are prefixed with `pluginVisualRegression`:
26+
27+
| Option | Config key |
28+
| ------------------------ | ---------------------------------------------- |
29+
| `updateImages` | `pluginVisualRegressionUpdateImages` |
30+
| `cleanupUnusedImages` | `pluginVisualRegressionCleanupUnusedImages` |
31+
| `diffConfig` | `pluginVisualRegressionDiffConfig` |
32+
| `forceDeviceScaleFactor` | `pluginVisualRegressionForceDeviceScaleFactor` |
33+
| `maxDiffThreshold` | `pluginVisualRegressionMaxDiffThreshold` |
34+
35+
### CLI
36+
37+
```bash
38+
# Before (deprecated in 15.10, removed in 16)
39+
npx cypress run --env "pluginVisualRegressionUpdateImages=true"
40+
41+
# After (Cypress ≥ 15.10)
42+
npx cypress run --expose "pluginVisualRegressionUpdateImages=true"
43+
```
44+
45+
### cypress.config.ts
46+
47+
```ts
48+
// Before
49+
export default defineConfig({
50+
env: {
51+
pluginVisualRegressionUpdateImages: true,
52+
pluginVisualRegressionDiffConfig: { threshold: 0.01 },
53+
},
54+
});
55+
56+
// After (Cypress ≥ 15.10)
57+
export default defineConfig({
58+
expose: {
59+
pluginVisualRegressionUpdateImages: true,
60+
pluginVisualRegressionDiffConfig: { threshold: 0.01 },
61+
},
62+
});
63+
```
64+
65+
### cypress.env.json
66+
67+
`cypress.env.json` only works with `Cypress.env()` and is not supported by the `expose` API.
68+
Migrate any plugin options from `cypress.env.json` into the `expose` block of `cypress.config.ts`.
69+
70+
```jsonc
71+
// cypress.env.json — REMOVE these plugin keys:
72+
{
73+
// "pluginVisualRegressionUpdateImages": true, ← move to cypress.config.ts expose block
74+
}
75+
```
76+
77+
### Supporting both Cypress 15.x and 16.x simultaneously
78+
79+
If you need your config to work on both Cypress 15.9 and below **and** 15.10+, you can supply the
80+
option in both places — the plugin will prefer `expose` on newer Cypress and fall back to `env` on
81+
older ones:
82+
83+
```ts
84+
export default defineConfig({
85+
expose: {
86+
pluginVisualRegressionUpdateImages: true,
87+
},
88+
env: {
89+
pluginVisualRegressionUpdateImages: true, // fallback for Cypress < 15.10
90+
},
91+
});
92+
```
93+
94+
### References
95+
96+
- [Cypress `Cypress.env()` migration guide](https://docs.cypress.io/app/references/migration-guide#Migrating-away-from-Cypressenv)
97+
- [Cypress `expose` API docs](https://on.cypress.io/expose)
98+
- [Issue #375](https://github.com/FRSOURCE/cypress-plugin-visual-regression-diff/issues/375)

packages/cypress-plugin-visual-regression-diff/README.md

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,12 @@ Still got troubles with installation? Have a look at [examples directory of this
158158
## Automatic clean up of unused images
159159

160160
It's useful to remove screenshots generated by the visual regression plugin that are not used by any test anymore.
161-
Enable this feature via env variable and enjoy freed up storage space 🚀:
161+
Enable this feature via expose variable and enjoy freed up storage space 🚀:
162162

163163
```bash
164+
# Cypress 15.10+
165+
npx cypress run --expose "pluginVisualRegressionCleanupUnusedImages=true"
166+
# Cypress <15.10 (deprecated in 15.10, removed in 16)
164167
npx cypress run --env "pluginVisualRegressionCleanupUnusedImages=true"
165168
```
166169

@@ -216,33 +219,40 @@ cy.matchImage({
216219
});
217220
```
218221

219-
- via [global env configuration](https://docs.cypress.io/guides/guides/environment-variables#Setting). Environment variable names are the same as keys of the configuration object above, but with added `pluginVisualRegression` prefix, e.g.:
222+
- via [global expose configuration](https://on.cypress.io/expose) (Cypress 15.10+). Configuration key names are the same as the keys of the configuration object above, but with added `pluginVisualRegression` prefix, e.g.:
220223

221224
```bash
225+
# Cypress 15.10+
226+
npx cypress run --expose "pluginVisualRegressionUpdateImages=true" --expose "pluginVisualRegressionDiffConfig={\"threshold\":0.01}"
227+
# Cypress <15.10 (deprecated in 15.10, removed in 16)
222228
npx cypress run --env "pluginVisualRegressionUpdateImages=true,pluginVisualRegressionDiffConfig={\"threshold\":0.01}"
223229
```
224230

225231
```ts
226-
// cypress.config.ts
232+
// cypress.config.ts (Cypress 15.10+)
227233
import { defineConfig } from 'cypress';
228234

229235
export default defineConfig({
230-
env: {
236+
expose: {
231237
pluginVisualRegressionUpdateImages: true,
232238
pluginVisualRegressionDiffConfig: { threshold: 0.01 },
233239
},
234240
});
235241
```
236242

237-
```json
238-
// cypress.env.json (https://docs.cypress.io/guides/guides/environment-variables#Option-2-cypress-env-json)
239-
{
240-
"pluginVisualRegressionUpdateImages": true,
241-
"pluginVisualRegressionDiffConfig": { "threshold": 0.01 }
242-
}
243+
```ts
244+
// cypress.config.ts (Cypress <15.10, deprecated in newer versions)
245+
import { defineConfig } from 'cypress';
246+
247+
export default defineConfig({
248+
env: {
249+
pluginVisualRegressionUpdateImages: true,
250+
pluginVisualRegressionDiffConfig: { threshold: 0.01 },
251+
},
252+
});
243253
```
244254

245-
For more ways of setting environment variables [take a look here](https://docs.cypress.io/guides/guides/environment-variables#Setting).
255+
For more ways of setting expose variables [take a look here](https://on.cypress.io/expose).
246256

247257
## FAQ
248258

@@ -269,9 +279,12 @@ This is typically caused by device pixel ratio differences between headless and
269279
cy.matchImage({ forceDeviceScaleFactor: true });
270280
```
271281

272-
Or set it globally via environment variable:
282+
Or set it globally via expose variable:
273283

274284
```bash
285+
# Cypress 15.10+
286+
npx cypress run --expose "pluginVisualRegressionForceDeviceScaleFactor=true"
287+
# Cypress <15.10 (deprecated in 15.10, removed in 16)
275288
npx cypress run --env "pluginVisualRegressionForceDeviceScaleFactor=true"
276289
```
277290

@@ -340,9 +353,12 @@ Set `maxDiffThreshold` to `0`:
340353
cy.matchImage({ maxDiffThreshold: 0 });
341354
```
342355

343-
Or globally via an environment variable:
356+
Or globally via an expose variable:
344357

345358
```bash
359+
# Cypress 15.10+
360+
npx cypress run --expose "pluginVisualRegressionMaxDiffThreshold=0"
361+
# Cypress <15.10 (deprecated in 15.10, removed in 16)
346362
npx cypress run --env "pluginVisualRegressionMaxDiffThreshold=0"
347363
```
348364

packages/cypress-plugin-visual-regression-diff/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@frsource/cypress-plugin-visual-regression-diff",
33
"description": "Perform visual regression test with a nice GUI as help. 💅 Only for Cypress!",
4-
"version": "4.0.2",
4+
"version": "4.1.0",
55
"author": "Jakub Freisler <jakub.freisler@frsource.org>",
66
"homepage": "https://github.com/FRSOURCE/cypress-plugin-visual-regression-diff",
77
"repository": "https://github.com/FRSOURCE/cypress-plugin-visual-regression-diff.git",

packages/cypress-plugin-visual-regression-diff/src/commands.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { FAB_BADGE_CLASS, FILE_SUFFIX, LINK_PREFIX, TASK } from './constants';
2+
import { supportsExpose } from './version.utils';
23
import type pixelmatch from 'pixelmatch';
34
import * as Base64 from '@frsource/base64';
45
import type { CompareImagesTaskReturn, PendingDiffRecord } from './types';
@@ -58,9 +59,14 @@ const constructCypressError = (log: Cypress.Log, err: Error) => {
5859
const capitalize = (text: string) =>
5960
text.charAt(0).toUpperCase() + text.slice(1);
6061

61-
const getPluginEnv = <K extends keyof Cypress.MatchImageOptions>(key: K) =>
62-
Cypress.env(`pluginVisualRegression${capitalize(key)}`) as
63-
Cypress.MatchImageOptions[K] | undefined;
62+
const getPluginEnv = <K extends keyof Cypress.MatchImageOptions>(key: K) => {
63+
const envKey = `pluginVisualRegression${capitalize(key)}`;
64+
if (supportsExpose(Cypress.version)) {
65+
return Cypress.expose(envKey) as Cypress.MatchImageOptions[K] | undefined;
66+
}
67+
68+
return Cypress.env(envKey) as Cypress.MatchImageOptions[K] | undefined;
69+
};
6470

6571
const booleanOption = <K extends keyof Cypress.MatchImageOptions, Return>(
6672
options: Cypress.MatchImageOptions,

packages/cypress-plugin-visual-regression-diff/src/plugins.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ vi.mock('./afterScreenshot.hook.ts', () => ({
1111
}));
1212

1313
describe('initPlugin', () => {
14-
it('inits hooks', () => {
14+
it('inits hooks (Cypress <15.10, env API)', () => {
1515
const onMock = vi.fn();
1616
initPlugin(onMock, {
17+
version: '13.17.0',
1718
env: { pluginVisualRegressionForceDeviceScaleFactor: false },
1819
} as unknown as Cypress.PluginConfigOptions);
1920

@@ -22,4 +23,18 @@ describe('initPlugin', () => {
2223
expect(initTaskHook).toBeCalledTimes(1);
2324
expect(initAfterScreenshotHook).toBeCalledTimes(1);
2425
});
26+
27+
it('inits hooks (Cypress 15.10+, expose API)', () => {
28+
const onMock = vi.fn();
29+
initPlugin(onMock, {
30+
version: '15.10.0',
31+
expose: { pluginVisualRegressionForceDeviceScaleFactor: false },
32+
env: {},
33+
} as unknown as Cypress.PluginConfigOptions);
34+
35+
expect(onMock).toBeCalledWith('task', 'task');
36+
expect(onMock).toBeCalledWith('after:screenshot', 'after:screenshot');
37+
expect(initTaskHook).toBeCalledTimes(2);
38+
expect(initAfterScreenshotHook).toBeCalledTimes(2);
39+
});
2540
});

packages/cypress-plugin-visual-regression-diff/src/plugins.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { initTaskHook } from './task.hook';
22
import { initAfterScreenshotHook } from './afterScreenshot.hook';
3+
import { getPluginConfig } from './version.utils';
34

45
/* c8 ignore start */
56
const initForceDeviceScaleFactor = (on: Cypress.PluginEvents) => {
@@ -24,7 +25,10 @@ export const initPlugin = (
2425
config: Cypress.PluginConfigOptions,
2526
) => {
2627
/* c8 ignore start */
27-
if (config.env['pluginVisualRegressionForceDeviceScaleFactor'] !== false) {
28+
if (
29+
getPluginConfig(config, 'pluginVisualRegressionForceDeviceScaleFactor') !==
30+
false
31+
) {
2832
initForceDeviceScaleFactor(on);
2933
}
3034
/* c8 ignore stop */

0 commit comments

Comments
 (0)