Skip to content

feat: separate versioning for images #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@ Screenshots in Cypress do not scale to the viewport size by default. You can cha

</details>

<details><summary>I've upgraded version of this plugin and all on my baseline images has been automatically updated. Why?</summary>

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!

</details>

DIFF_IMAGES_VERSION

## Questions

Don’t hesitate to ask a question directly on the [discussions board](https://github.com/FRSOURCE/cypress-plugin-visual-regression-diff/discussions)!
Expand Down
10 changes: 7 additions & 3 deletions src/image.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ import sharp from "sharp";
import metaPngPkg from "meta-png";
const { addMetadata, getMetadata } = metaPngPkg;
import glob from "glob";
import { version } from "../package.json";
import { wasScreenshotUsed } from "./screenshotPath.utils";
import { METADATA_KEY } from "./constants";

// version of images generated by this plugin
// bump only when there is a breaking change to:
// image comparison or image generation algorithms
const DIFF_IMAGES_VERSION = "1";

export const addPNGMetadata = (png: Buffer) =>
addMetadata(png, METADATA_KEY, version /* c8 ignore next */);
addMetadata(png, METADATA_KEY, DIFF_IMAGES_VERSION /* c8 ignore next */);
export const getPNGMetadata = (png: Buffer) =>
getMetadata(png, METADATA_KEY /* c8 ignore next */);
export const isImageCurrentVersion = (png: Buffer) =>
getPNGMetadata(png) === version;
getPNGMetadata(png) === DIFF_IMAGES_VERSION;
export const isImageGeneratedByPlugin = (png: Buffer) =>
!!getPNGMetadata(png /* c8 ignore next */);

Expand Down