Skip to content

Commit

Permalink
feat: make pixelmatch options configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
kien-ht committed Aug 23, 2023
1 parent 3df0efd commit 26d86be
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ Currently supported values in the custom config file:
- FAILURE_THRESHOLD: must be between 0 and 1, default to 0
- RETRY_OPTIONS: see [retry options](https://www.npmjs.com/package/cypress-recurse#options)
- FAIL_ON_MISSING_BASELINE: a boolean to determine whether to fail a test if its baseline doesn't exist, default to false
- COMPARISON_OPTIONS: custom options passed to pixelmatch, see [pixelmatch options](https://github.com/mapbox/pixelmatch#api), default to `{ threshold: 0.1 }`. Please note that the `COMPARISON_OPTIONS.threshold` is different from the `FAILURE_THRESHOLD` above:
- `COMPARISON_OPTIONS.threshold`: is the failure threshold for every pixel comparision
- `FAILURE_THRESHOLD`: is the failure threshold for the whole comparision

> **Note**: In order to make this custom config values effective, remember to return `getCompareSnapshotsPlugin` instance inside function `setupNodeEvents`:
Expand Down
3 changes: 2 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const DEFAULT_CONFIG = {
ROOT_DIR: '',
FAILURE_THRESHOLD: 0,
RETRY_OPTIONS: {},
FAIL_ON_MISSING_BASELINE: false
FAIL_ON_MISSING_BASELINE: false,
COMPARISON_OPTIONS: { threshold: 0.1 }
}

export const userConfig = { ...DEFAULT_CONFIG, ...getUserConfigFile() }
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const getStatsComparisonAndPopulateDiffIfAny = async (args) => {
diff.data,
diff.width,
diff.height,
{ threshold: 0.1 }
userConfig.COMPARISON_OPTIONS
)

const percentage = (pixelMismatchResult / diff.width / diff.height) ** 0.5
Expand Down

0 comments on commit 26d86be

Please sign in to comment.