Skip to content

Commit

Permalink
Fixed aheckmann#465 hard coded gm binary, also fixed issues with comp…
Browse files Browse the repository at this point in the history
…are and fixed tests so they will fail on subsequent runs when they should do
  • Loading branch information
rwky committed Oct 26, 2015
1 parent 5f5c774 commit 4ad863b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 10 additions & 5 deletions lib/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ module.exports = exports = function (proto) {
function compare(orig, compareTo, options, cb) {

var isImageMagick = this._options && this._options.imageMagick;
// compare binary for IM is `compare`, for GM it's `gm compare`
var bin = isImageMagick ? '' : 'gm ';
var args = ['compare', '-metric', 'mse', orig, compareTo]
var appPath = this._options && this._options.appPath || '';
var bin = isImageMagick
? appPath + 'compare'
: appPath + 'gm'
var args = ['-metric', 'mse', orig, compareTo]
if (!isImageMagick) {
args.unshift('compare');
}
var tolerance = 0.4;
// outputting the diff image
if (typeof options === 'object') {
Expand All @@ -46,7 +51,7 @@ module.exports = exports = function (proto) {
args.push(options.highlightStyle)
}
// For IM, filename is the last argument. For GM it's `-file <filename>`
if (isImageMagick) {
if (!isImageMagick) {
args.push('-file');
}
args.push(options.file);
Expand All @@ -71,7 +76,7 @@ module.exports = exports = function (proto) {
}
}

var proc = spawn('/usr/bin/gm', args);
var proc = spawn(bin, args);
var stdout = '';
var stderr = '';
proc.stdout.on('data',function(data) { stdout+=data });
Expand Down
6 changes: 4 additions & 2 deletions test/422.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ module.exports = function (gm, dir, finish, GM) {
if (err) return finish(err);

fs.exists(options.file, function(exists) {
if (exists) finish();
if (exists) {
fs.unlink(options.file, finish);
}
else finish(new Error('Diff file does not exist.'));
});
});
});
});
});
};
};

0 comments on commit 4ad863b

Please sign in to comment.