Skip to content

Avoid crash on size mismatch #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ class ResembleHelper extends Helper {
/**
* Compare Images
*
* @param image1
* @param image2
* @param image
* @param diffImage
* @param options
* @returns {Promise<any | never>}
*/
async _compareImages(image1, image2, diffImage, options) {
image1 = this.config.baseFolder + image1;
image2 = this.config.screenshotFolder + image2;
async _compareImages(image, diffImage, options) {
const image1 = this.config.baseFolder + image;
const image2 = this.config.screenshotFolder + image;

return new Promise((resolve, reject) => {

Expand All @@ -40,7 +39,7 @@ class ResembleHelper extends Helper {
if (err) {
reject(err);
} else {
if(!data.isSameDimensions) throw new Error("The images are not of same dimensions. Please use images of same dimensions so as to avoid any unexpected results.")
if(!data.isSameDimensions) reject(new Error("The images are not of same dimensions. Please use images of same dimensions so as to avoid any unexpected results."));
resolve(data);
if (data.misMatchPercentage >= tolerance) {
mkdirp(getDirName(this.config.diffFolder + diffImage), function (err) {
Expand All @@ -63,14 +62,13 @@ class ResembleHelper extends Helper {

/**
*
* @param image1
* @param image
* @param options
* @returns {Promise<*>}
*/
async _fetchMisMatchPercentage(image1, options) {
const image2 = image1;
const diffImage = "Diff_" + image1.split(".")[0];
const result = this._compareImages(image1, image2, diffImage, options);
async _fetchMisMatchPercentage(image, options) {
const diffImage = "Diff_" + image.split(".")[0];
const result = this._compareImages(image, diffImage, options);
const data = await Promise.resolve(result);
return data.misMatchPercentage;
}
Expand Down