Skip to content

Conversation

@wswebcreation
Copy link
Member

@wswebcreation wswebcreation commented Jan 31, 2026

Summary

Fixes #1111 - When using visual matchers like toMatchScreenSnapshot('tag', 0.9) with alwaysSaveActualImage: false, the actual image was still being saved even when the comparison passed within the threshold.

Root Cause

There were two disconnected threshold systems:

  1. Core (images.ts): Used saveAboveTolerance (defaulting to 0) to decide whether to save images
  2. Matcher (matcher.ts): Used the user-provided expected threshold to determine pass/fail

When a user set a threshold like 0.9, the core didn't know about it - it still used the default 0, causing images to be saved for any non-zero mismatch.

Solution

The matcher now passes the expected threshold to the core as saveAboveTolerance in the parseMatcherParams function:

  • Numeric thresholds are passed directly
  • When no threshold is provided, defaults to 0 (matching existing behavior)
  • User-provided saveAboveTolerance is respected (not overridden)
  • Asymmetric matchers (e.g., expect.any(Number)) cannot be converted to numeric, so default behavior is used

Example

Before (broken):

Component Threshold Decision
Core saveAboveTolerance: 0 (default) 0.05 > 0 → save image
Matcher expected: 0.9 0.05 <= 0.9 → test passes

After (fixed):

Component Threshold Decision
Core saveAboveTolerance: 0.9 (from matcher) 0.05 > 0.9 = false → don't save
Matcher expected: 0.9 0.05 <= 0.9 → test passes

Test plan

  • Added unit tests for threshold passthrough to all matcher functions
  • Added tests for default behavior (no threshold → 0)
  • Added tests for user-provided saveAboveTolerance (no override)
  • Added tests for asymmetric matchers
  • All 827 existing tests pass

When using visual matchers with a threshold (e.g., toMatchScreenSnapshot('tag', 0.9))
and alwaysSaveActualImage: false, images were still saved even when the comparison
passed within the threshold.

The matcher now passes the expected threshold to the core as saveAboveTolerance,
ensuring images are only saved when mismatch exceeds the user's acceptable threshold.

Fixes #1111

Co-authored-by: Cursor <cursoragent@cursor.com>
@changeset-bot
Copy link

changeset-bot bot commented Jan 31, 2026

🦋 Changeset detected

Latest commit: 95b3b79

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@wdio/visual-service Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@wswebcreation wswebcreation merged commit 2a518ff into main Jan 31, 2026
11 checks passed
@wswebcreation wswebcreation deleted the fix/always-save-actual-image-threshold branch January 31, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

alwaysSaveActualImage: false does not respect comparison threshold larger than 0

2 participants