Fixed #465 hard coded gm binary, also fixed issues with compare and fixed tests so they will fail on subsequent runs when they should do

master
Rowan Wookey 9 years ago
parent 5f5c77490a
commit 4ad863b0c4
  1. 15
      lib/compare.js
  2. 6
      test/422.js

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

@ -29,11 +29,13 @@ module.exports = function (gm, dir, finish, GM) {
if (err) return finish(err); if (err) return finish(err);
fs.exists(options.file, function(exists) { 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.')); else finish(new Error('Diff file does not exist.'));
}); });
}); });
}); });
}); });
}); });
}; };

Loading…
Cancel
Save