diff --git a/README.md b/README.md index 66f888d..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. +`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 680741d..41e6653 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) || + (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) } @@ -357,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." ); + } } /**