gemini-testing / looks-same

Node.js library for comparing images
MIT License
669 stars 55 forks source link

Options mutation yields 'Unable to use "strict" and "tolerance" options together' error. #41

Open Izhaki opened 6 years ago

Izhaki commented 6 years ago

Snippet:

const getImageDiff = async (reference, current) => new Promise((resolve, reject) => {
  const options = {
    highlightColor: '#ff00ff',
    strict: true,
  };

  looksSame(reference, current, options, function(error, equal) {
    if (error) reject(error);
    if (!equal) {
      looksSame.createDiff({reference, current, ...options}, function(error, buffer) {
        if (error) reject(error);
        resolve(buffer);
      });
    }
    resolve();
  });
});

Will throw:

Unable to use "strict" and "tolerance" options together

This happens on looksSame.createDiff() since looksSame() mutates the options to look like this:

{ 
  highlightColor: '#ff00ff',
  strict: true,
  tolerance: 2.3,
  ignoreAntialiasing: true,
  antialiasingTolerance: 0 
}

PS. Would be grand to have equal returned with createDiff: looksSame.createDiff(options, function(error, buffer, equal) would save some of the logic above.

scottrippey commented 5 years ago

Had the same problem, thank you for finding this! The workaround I'm using is along these lines:

looksSame(baseline, actual, { ... options }, (err, { equal }) => {
  if (equal) return;
  looksSame.createDiff({
    reference: baseline,
    current: actual,
    ...options
  });
);

But I would appreciate an actual fix!