Skip to content

Commit

Permalink
fix: logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent committed Jun 11, 2024
1 parent 58b16c8 commit e213ace
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ It can be used by adding the *aws* code inside `"ResembleHelper"` in the `"helpe
"secretAccessKey": "<Your secretAccessKey>",
"region": "<Region of Bucket>",
"bucketName": "<Bucket Name>",
"skipS3Upload": true,
"uploadOnlyBaseImage": true,
}
}
}
Expand All @@ -184,7 +184,7 @@ This base image has to be located inside a folder named "*base*".
The resultant output image will be uploaded in a folder named "*output*" and diff image will be uploaded to a folder named "*diff*" in the S3 bucket.
If the `prepareBaseImage` option is marked `true`, then the generated base image will be uploaded to a folder named "*base*" in the S3 bucket.
> Note: The tests may take a bit longer to run when the AWS configuration is provided as determined by the internet speed to upload/download images.
> Note: if you want to skip the s3 upload, set skipS3Upload to true.
> Note: if you want to skip the s3 upload for other folders like diff or output, set `uploadOnlyBaseImage` to true, then only base folder is uploaded to S3.
### Other S3 Providers
The same configuration as above, but with *endpoint* field:
Expand Down
58 changes: 31 additions & 27 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ class ResembleHelper extends Helper {
baseImage: any,
options: any,
endpoint: Endpoint,
uploadOnlyBaseImage: boolean,
) {
console.log("Starting Upload... ");
const s3 = new AWS.S3({
Expand All @@ -289,6 +290,35 @@ class ResembleHelper extends Helper {
region: region,
endpoint,
});

// If prepareBaseImage is false, then it won't upload the baseImage. However, this parameter is not considered if the config file has a prepareBaseImage set to true.
if (this._getPrepareBaseImage(options)) {
const baseImageName = this._getBaseImageName(baseImage, options);

fs.readFile(this._getBaseImagePath(baseImage, options), (err: any, data: any) => {
if (err) throw err;
else {
const base64data = new Buffer(data, "binary");
const params = {
Bucket: bucketName,
Key: `base/${baseImageName}`,
Body: base64data,
};
s3.upload(params, (uErr: any, uData: { Location: any }) => {
if (uErr) throw uErr;
console.log(`Base Image uploaded at ${uData.Location}`);
});
}
});
} else {
console.log("Not Uploading base Image");
}

if (uploadOnlyBaseImage) {
this.debug("Only the Base Image is uploaded to S3. Skipping upload of diff and output folders!");
return;
}

fs.readFile(this._getActualImagePath(baseImage), (err: any, data: any) => {
if (err) throw err;
const base64data = new Buffer(data, "binary");
Expand Down Expand Up @@ -317,29 +347,6 @@ class ResembleHelper extends Helper {
});
}
});

// If prepareBaseImage is false, then it won't upload the baseImage. However, this parameter is not considered if the config file has a prepareBaseImage set to true.
if (this._getPrepareBaseImage(options)) {
const baseImageName = this._getBaseImageName(baseImage, options);

fs.readFile(this._getBaseImagePath(baseImage, options), (err: any, data: any) => {
if (err) throw err;
else {
const base64data = new Buffer(data, "binary");
const params = {
Bucket: bucketName,
Key: `base/${baseImageName}`,
Body: base64data,
};
s3.upload(params, (uErr: any, uData: { Location: any }) => {
if (uErr) throw uErr;
console.log(`Base Image uploaded at ${uData.Location}`);
});
}
});
} else {
console.log("Not Uploading base Image");
}
}

/**
Expand Down Expand Up @@ -441,9 +448,6 @@ class ResembleHelper extends Helper {
await this._addAttachment(baseImage, misMatch, options);
await this._addMochaContext(baseImage, misMatch, options);
if (awsC !== undefined) {
if (awsC.skipS3Upload) {
this.debug("Uploading to S3 is skipped due to skipS3Upload is set");
} else {
await this._upload(
awsC.accessKeyId,
awsC.secretAccessKey,
Expand All @@ -452,8 +456,8 @@ class ResembleHelper extends Helper {
baseImage,
options,
awsC.endpoint,
awsC.uploadOnlyBaseImage
);
}
}

this.debug(`MisMatch Percentage Calculated is ${misMatch} for baseline ${baseImage}`);
Expand Down

0 comments on commit e213ace

Please sign in to comment.