-
Notifications
You must be signed in to change notification settings - Fork 94
Is there any way to test a threshold? #14
Comments
Currently, it is a strict comparison to https://github.com/uber/image-diff/blob/1.0.1/lib/image-diff.js#L85 imageDiff({
actualImage: 'checkerboard.png',
expectedImage: 'white.png',
diffImage: 'difference.png',
threshold: 20 // percentage of 100
}, ... Would that work for your case? |
@twolfson Absolutely! This would be perfect and I'd implement it in testing suites across a couple of my libraries immediately! 💃 |
Cool. I am pretty busy with some other things at the moment but I will take a look by the end of next weekend. Feel free to open a PR to beat me to the punch =) |
https://github.com/uber/image-diff/blob/1.0.1/lib/image-diff.js#L72 |
Nah, |
I think this is probably out of my JS skill range and I'm in no big rush so I'm happy to wait on your expertise to implement this the correct way. =) Pretty professional way of saying, "I R DUM." |
Not a problem. My ETA still stands. Fwiw, the approach would be something like change the regexp grouping to evaluate the perecentage, parse it to a float, and perform a comparison. The partially tedious part would be writing a test. https://github.com/uber/image-diff/blob/1.0.1/lib/image-diff.js#L76-L85 // Parse the percentage difference
var percentDifference = parseFloat(resultInfo[2], 10);
if (isNaN(percentDifference)) {
return cb(new Error('Attempted to parse percentage difference from `image-diff\'s stderr` but got `NaN` from "' + resultInfo[2] + '"'));
}
// Callback with pass/fail
return cb(null, percentageDifference <= thresholdDifference); |
Well, I'll wait until it's implemented then I'll tackle the issue of coming up with a nice standard way to do visual tests with it. Really appreciate your work on this. |
@twolfson I am new to git and cannot push but here is the diff output of what I have done which works perfectly by providing a threshold and also returns the path+name of the diff image (so, that the user may delete if blank) diff --git a/lib/image-diff.js b/lib/image-diff.js
// If there was no resultInfo, throw a fit // Callback with pass/fail
// Assert our options are passed in
|
Ok, the diff does not appear properly with "plus" and "minus" signs - I have to see how to properly branch and submit |
If you have problems, can you just https://gist.github.com your updated code? |
Ok done, thanks. Nick On Mon, Mar 30, 2015 at 8:48 AM, Cory Simmons [email protected]
|
More GitHub related info can be found here: |
@corysimmons Just FYI, use it today with |
@bevacqua Nice! Thanks for pinging me. =) |
Can you open Issues on your fork? |
Sure but I won't be improving it, it's just temporary because I needed it asap |
Was just gonna ask for some docs. |
Ah, that I can do |
👍 |
Reopening this in hopes of uniting the two libraries. I can open a proper PR for this if you'd be interested in merging. |
@corysimmons It looks like #15 was ready to be merged but we never got a squash so we closed it due to inactivity =/ You can probably reuse that code or start fresh |
For instance, is there a way to test for a suitable level of difference?
My use case is I have a grid system in Sass and Stylus. They produce very very slightly different widths. As long as it's generally around the same width, I'd like tests to pass.
This lib seems like it'd fail unless the widths are the exact same.
The text was updated successfully, but these errors were encountered: