Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: provide an opt to skip s3 upload #140

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,19 @@ 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": "<location of base folder>",
"diffFolder": "<location of diff folder>",
"aws": {
"accessKeyId" : "<Your AccessKeyId>",
"secretAccessKey": "<Your secretAccessKey>",
"region": "<Region of Bucket>",
"bucketName": "<Bucket Name>"
"bucketName": "<Bucket Name>",
"uploadOnlyBaseImage": true,
}
}
}
Expand All @@ -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:
Expand Down
54 changes: 31 additions & 23 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 @@ -449,6 +456,7 @@ class ResembleHelper extends Helper {
baseImage,
options,
awsC.endpoint,
awsC.uploadOnlyBaseImage,
);
}

Expand Down
Loading