Skip to content

Commit

Permalink
Extended Callback: Now the compare callback will also return the orig…
Browse files Browse the repository at this point in the history
…inal as well as the compareTo filename so it can be used in the callback method in order to tell the user which files had problems or were not equal to each other.
  • Loading branch information
Sascha Sambale committed Jun 27, 2014
1 parent 02bef0d commit 631beec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = exports = function (proto) {
// compare binary for IM is `compare`, for GM it's `gm compare`
var bin = isImageMagick ? '' : 'gm ';
var execCmd = bin + 'compare -metric mse ' + orig + ' ' + compareTo;
var tolerance = 0.4
var tolerance = 0.4;
// outputting the diff image
if (typeof options === 'object') {
if (options.file) {
Expand Down Expand Up @@ -88,7 +88,7 @@ module.exports = exports = function (proto) {
}

var equality = parseFloat(match[1]);
cb(null, equality <= tolerance, equality, stdout);
cb(null, equality <= tolerance, equality, stdout, utils.unescape(orig), utils.unescape(compareTo));
});
}

Expand Down
8 changes: 6 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@

exports.escape = function escape (arg) {
return '"' + String(arg).trim().replace(/"/g, '\\"') + '"';
}
};

exports.unescape = function escape (arg) {
return String(arg).trim().replace(/"/g, "");
};

exports.argsToArray = function (args) {
var arr = [];
Expand All @@ -20,4 +24,4 @@ exports.argsToArray = function (args) {
}

return arr;
}
};

0 comments on commit 631beec

Please sign in to comment.