diff --git a/README.md b/README.md index cb42a87..1f33fd7 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ It can be used by adding the *aws* code inside `"ResembleHelper"` in the `"helpe "secretAccessKey": "", "region": "", "bucketName": "", - "skipS3Upload": true, + "uploadOnlyBaseImage": true, } } } @@ -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: diff --git a/src/index.ts b/src/index.ts index a22324f..316a7fc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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({ @@ -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"); @@ -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"); - } } /** @@ -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, @@ -452,8 +456,8 @@ class ResembleHelper extends Helper { baseImage, options, awsC.endpoint, + awsC.uploadOnlyBaseImage ); - } } this.debug(`MisMatch Percentage Calculated is ${misMatch} for baseline ${baseImage}`);