gemini-testing / gemini-testing/looks-same

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

Open
#41 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
827
Forks
55
PR merge metrics
No merged PRs in 30d

Description

Snippet:
```javascript
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:

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

- I don't think any operation should mutate the options object since it is owned by the client code.
- Especially not so if this mutates it into an invalid state.

---

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.