Skip to content

Commit 37fdea4

Browse files
committed
feat: separate versioning for images
Signed-off-by: Jakub Freisler <[email protected]>
1 parent 1e70d9e commit 37fdea4

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@ Screenshots in Cypress do not scale to the viewport size by default. You can cha
248248

249249
</details>
250250

251+
<details><summary>I've upgraded version of this plugin and all on my baseline images has been automatically updated. Why?</summary>
252+
253+
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!
254+
255+
</details>
256+
257+
DIFF_IMAGES_VERSION
258+
251259
## Questions
252260

253261
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

Lines changed: 7 additions & 3 deletions
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)