@@ -73,16 +73,20 @@ ImageDiff.createDiff = function (options, cb) {
73
73
// DEV: According to http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=17284
74
74
// DEV: These values are the total square root mean square (RMSE) pixel difference across all pixels and its percentage
75
75
// TODO: This is not very multi-lengual =(
76
- var resultInfo = stderr . match ( / a l l : ( \d + \. ? \d * ) \( ( . * ? ) \) / ) ;
76
+ var resultInfo = stderr . match ( / a l l : ( \d + \. ? \d * ) \( ( \d + \. ? \d * e ? \- ? \d * ) \) / ) ;
77
77
78
78
// If there was no resultInfo, throw a fit
79
79
if ( ! resultInfo ) {
80
80
return cb ( new Error ( 'Expected `image-diff\'s stderr` to contain \'all\' but received "' + stderr + '"' ) ) ;
81
81
}
82
82
83
83
// Callback with pass/fail
84
- var totalDifference = resultInfo [ 2 ] ; // this is the percentage difference
85
- return cb ( null , parseFloat ( totalDifference ) <= options . threshold , options . diffPath ) ;
84
+ var percentDifference = parseFloat ( resultInfo [ 2 ] , 10 ) ;
85
+ var threshold = ( typeof ( options . threshold ) === 'undefined' || isNaN ( parseFloat ( options . threshold , 10 ) ) ) ? 0.0 : parseFloat ( options . threshold ) ;
86
+ if ( isNaN ( percentDifference ) ) {
87
+ return cb ( new Error ( 'Attempted to parse percentage difference from `image-diff\'s stderr` but got `NaN` from "' + resultInfo [ 2 ] + '"' ) ) ;
88
+ }
89
+ return cb ( null , percentDifference <= threshold ) ;
86
90
} ) ;
87
91
} ;
88
92
ImageDiff . prototype = {
@@ -190,9 +194,8 @@ ImageDiff.prototype = {
190
194
expectedPath : expectedTmpPath ,
191
195
diffPath : diffPath ,
192
196
threshold : threshold
193
- } , function saveResult ( err , _imagesAreSame , _diffPath ) {
197
+ } , function saveResult ( err , _imagesAreSame ) {
194
198
imagesAreSame = _imagesAreSame ;
195
- diffPath = _diffPath ;
196
199
cb ( err ) ;
197
200
} ) ;
198
201
}
@@ -205,7 +208,7 @@ ImageDiff.prototype = {
205
208
fs . unlink ( filepath , cb ) ;
206
209
} , function callOriginalCallback ( _err ) {
207
210
// Callback with the imagesAreSame
208
- callback ( err , imagesAreSame , diffPath ) ;
211
+ callback ( err , imagesAreSame ) ;
209
212
} ) ;
210
213
} ) ;
211
214
}
0 commit comments