From b9643ac74a51df12b45bb03f335fca0e43dbdb7a Mon Sep 17 00:00:00 2001 From: jamrip01 Date: Wed, 23 Dec 2020 18:40:19 +0100 Subject: [PATCH 1/2] fix prepareBaseImage condition --- README.md | 2 +- index.js | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 66f888d..0cb00a8 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ To use the Helper, users may provide the parameters: `diffFolder`: Mandatory. This will the folder where resemble would try to store the difference image, which can be viewed later. -`prepareBaseImage`: Optional. When `true` then the system replaces all of the baselines related to the test case(s) you ran. This is equivalent of setting the option `prepareBaseImage: true` in all verifications of the test file. +`prepareBaseImage`: Optional. When `true` then the system replaces all of the baselines related to the test case(s) you ran. This is equivalent of setting the option `prepareBaseImage: true` in all verifications of the test file. If this parameter is not used in `.conf` file, `codeceptjs-resemblehelper` automatically set default value as `true`. ### Usage diff --git a/index.js b/index.js index 680741d..df8886d 100644 --- a/index.js +++ b/index.js @@ -308,6 +308,10 @@ class ResembleHelper extends Helper { options.tolerance = 0; } + if (!options.tolerance){ + options.tolerance = 0; + } + const prepareBaseImage = options.prepareBaseImage !== undefined ? options.prepareBaseImage : (this.prepareBaseImage === true) @@ -315,15 +319,19 @@ class ResembleHelper extends Helper { if (awsC !== undefined && prepareBaseImage === false) { await this._download(awsC.accessKeyId, awsC.secretAccessKey, awsC.region, awsC.bucketName, baseImage); } - if (options.prepareBaseImage !== undefined && options.prepareBaseImage) { + if ( + (this.prepareBaseImage === true && + options.prepareBaseImage === undefined) || + (this.prepareBaseImage !== undefined && options.prepareBaseImage === true) + ) { await this._prepareBaseImage(baseImage); } if (selector) { options.boundingBox = await this._getBoundingBox(selector); } const misMatch = await this._fetchMisMatchPercentage(baseImage, options); - this._addAttachment(baseImage, misMatch, options.tolerance); - this._addMochaContext(baseImage, misMatch, options.tolerance); + await this._addAttachment(baseImage, misMatch, options.tolerance); + await this._addMochaContext(baseImage, misMatch, options.tolerance); if (awsC !== undefined) { await this._upload(awsC.accessKeyId, awsC.secretAccessKey, awsC.region, awsC.bucketName, baseImage, options.prepareBaseImage) } From 4eb639a03e7369fc44c11b901d9123192d34855a Mon Sep 17 00:00:00 2001 From: jamrip01 Date: Mon, 4 Jan 2021 18:49:15 +0100 Subject: [PATCH 2/2] add logic for existing base image --- README.md | 2 +- index.js | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0cb00a8..f1aef64 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ To use the Helper, users may provide the parameters: `diffFolder`: Mandatory. This will the folder where resemble would try to store the difference image, which can be viewed later. -`prepareBaseImage`: Optional. When `true` then the system replaces all of the baselines related to the test case(s) you ran. This is equivalent of setting the option `prepareBaseImage: true` in all verifications of the test file. If this parameter is not used in `.conf` file, `codeceptjs-resemblehelper` automatically set default value as `true`. +`prepareBaseImage`: Optional. When `true` then the system replaces all of the baselines related to the test case(s) you ran. This is equivalent of setting the option `prepareBaseImage: true` in all verifications of the test file. If this parameter is not used in `.conf` file, value is `undefined`. ### Usage diff --git a/index.js b/index.js index df8886d..41e6653 100644 --- a/index.js +++ b/index.js @@ -322,7 +322,7 @@ class ResembleHelper extends Helper { if ( (this.prepareBaseImage === true && options.prepareBaseImage === undefined) || - (this.prepareBaseImage !== undefined && options.prepareBaseImage === true) + (options.prepareBaseImage === true) ) { await this._prepareBaseImage(baseImage); } @@ -365,7 +365,13 @@ class ResembleHelper extends Helper { } }); - fs.copyFileSync(this.screenshotFolder + screenShotImage, this.baseFolder + screenShotImage); + try { + await fs.promises.access(this.baseFolder + screenShotImage, fs.constants.F_OK | fs.constants.W_OK); + this.debug("Existing base image is used from: " + this.baseFolder + screenShotImage); + } catch(e){ + fs.copyFileSync(this.screenshotFolder + screenShotImage, this.baseFolder + screenShotImage); + this.debug("Base image: " + screenShotImage + " was created." ); + } } /**