From d19c3ebe7d566fb225767c814b5046855bec2cd2 Mon Sep 17 00:00:00 2001 From: Joshua Stoutenburg Date: Tue, 29 Aug 2023 10:14:58 -0600 Subject: [PATCH] Add pixelmatchThreshold image config --- src/config.js | 1 + src/utils/tasks/imageSnapshots.js | 2 +- types/index.d.ts | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/config.js b/src/config.js index 65f6a1e3..b613f66a 100644 --- a/src/config.js +++ b/src/config.js @@ -20,6 +20,7 @@ const DEFAULT_SCREENSHOT_CONFIG = Object.freeze({ const DEFAULT_IMAGE_CONFIG = Object.freeze({ createDiffImage: true, resizeDevicePixelRatio: true, + pixelmatchThreshold: 0.01, threshold: 0.1, thresholdType: 'percent', // can be 'percent' or 'pixel' }); diff --git a/src/utils/tasks/imageSnapshots.js b/src/utils/tasks/imageSnapshots.js index d1d5dfa9..984ff344 100644 --- a/src/utils/tasks/imageSnapshots.js +++ b/src/utils/tasks/imageSnapshots.js @@ -106,7 +106,7 @@ function compareImages(expected, actual, diffFilename, config) { const imageConfig = merge({}, DEFAULT_IMAGE_CONFIG, config); const pixelmatchConfig = { - threshold: 0.01, + threshold: imageConfig.pixelmatchThreshold, }; const imageWidth = actual.image.width; diff --git a/types/index.d.ts b/types/index.d.ts index 8c92b89e..bd865879 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -20,6 +20,7 @@ declare namespace Cypress { toMatchImageSnapshot(options?: Partial<{ imageConfig: Partial<{ createDiffImage: boolean, + pixelmatchThreshold: number, threshold: number, thresholdType: "percent" | "pixels", resizeDevicePixelRatio: boolean