Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 18 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,22 +308,30 @@ class ResembleHelper extends Helper {
options.tolerance = 0;
}

if (!options.tolerance){
options.tolerance = 0;
}

const prepareBaseImage = options.prepareBaseImage !== undefined
? options.prepareBaseImage
: (this.prepareBaseImage === true)
const awsC = this.config.aws;
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)
}
Expand Down Expand Up @@ -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." );
}
}

/**
Expand Down