Skip to content

Commit b2a7434

Browse files
authored
feat: separate versioning for images (#221)
closes #197
1 parent 2aef358 commit b2a7434

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,14 @@ Screenshots in Cypress do not scale to the viewport size by default. You can cha
251251

252252
</details>
253253

254+
<details><summary>I've upgraded version of this plugin and all on my baseline images has been automatically updated. Why?</summary>
255+
256+
Sometimes we need to do a breaking change in image comparison or image generation algorithms. To provide you with the easiest upgrade path - the plugin updates your baseline images automatically. Just commit them to your repository after the plugin upgrade and you are good to go!
257+
258+
</details>
259+
260+
DIFF_IMAGES_VERSION
261+
254262
## Questions
255263

256264
Don’t hesitate to ask a question directly on the [discussions board](https://github.com/FRSOURCE/cypress-plugin-visual-regression-diff/discussions)!

src/image.utils.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@ import sharp from "sharp";
55
import metaPngPkg from "meta-png";
66
const { addMetadata, getMetadata } = metaPngPkg;
77
import glob from "glob";
8-
import { version } from "../package.json";
98
import { wasScreenshotUsed } from "./screenshotPath.utils";
109
import { METADATA_KEY } from "./constants";
1110

11+
// version of images generated by this plugin
12+
// bump only when there is a breaking change to:
13+
// image comparison or image generation algorithms
14+
const DIFF_IMAGES_VERSION = "1";
15+
1216
export const addPNGMetadata = (png: Buffer) =>
13-
addMetadata(png, METADATA_KEY, version /* c8 ignore next */);
17+
addMetadata(png, METADATA_KEY, DIFF_IMAGES_VERSION /* c8 ignore next */);
1418
export const getPNGMetadata = (png: Buffer) =>
1519
getMetadata(png, METADATA_KEY /* c8 ignore next */);
1620
export const isImageCurrentVersion = (png: Buffer) =>
17-
getPNGMetadata(png) === version;
21+
getPNGMetadata(png) === DIFF_IMAGES_VERSION;
1822
export const isImageGeneratedByPlugin = (png: Buffer) =>
1923
!!getPNGMetadata(png /* c8 ignore next */);
2024

0 commit comments

Comments
 (0)