diff --git a/README.md b/README.md index 333cc20..1f33fd7 100644 --- a/README.md +++ b/README.md @@ -161,10 +161,10 @@ Set `output` to where the generated report is to be stored. Default is the outpu ### AWS Support AWS S3 support to upload and download various images is also provided. It can be used by adding the *aws* code inside `"ResembleHelper"` in the `"helpers"` section in config file. The final result should look like: -```json +```js { "helpers": { - "ResembleHelper" : { + "ResembleHelper": { "require": "codeceptjs-resemblehelper", "baseFolder": "", "diffFolder": "", @@ -172,7 +172,8 @@ It can be used by adding the *aws* code inside `"ResembleHelper"` in the `"helpe "accessKeyId" : "", "secretAccessKey": "", "region": "", - "bucketName": "" + "bucketName": "", + "uploadOnlyBaseImage": true, } } } @@ -183,6 +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 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 99120fd..675d4fa 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"); - } } /** @@ -449,6 +456,7 @@ class ResembleHelper extends Helper { baseImage, options, awsC.endpoint, + awsC.uploadOnlyBaseImage, ); }