Skip to content

Calculation of image difference percentage is incorrect #107

Closed
@NathanielAvery

Description

@NathanielAvery

Hi 👋🏻 Thanks for writing this plugin!

Describe the bug

When the plugin determines the percentage of changed pixels, its calculation is incorrect:

imgDiff = (diffPixels / width) * height;

As pixelmatch returns the number of different pixels, this line should be:

imgDiff = diffPixels / (width * height); 

To Reproduce

  • Create an empty 100x100 <div> element
  • Capture a snapshot of that element in a Cypress test with a threshold of 0.5.
  • Modify the snapshot image so that just below 50% of the pixels are different.
  • Re-run the test.
  • Expected behavior: Test passes.
  • Actual behavior: Test fails.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions