Skip to content

Naive implementation of using different endpoints in aws-sdk #107

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

Merged
merged 1 commit into from
Jan 2, 2023
Merged
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
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,28 @@ The resultant output image will be uploaded in a folder named "*output*" and dif
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.

### Other S3 Providers
The same configuration as above, but with *endpoint* field:

```json
{
"helpers": {
"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>",
"endpoint": "<Endpoint of Bucket>"
}
}
}
}
```

### Compare with custom image
Usually, every screenshot needs to have the same filename as an existing image inside the `baseFolder` directory. To change this behavior, you can use the `compareWithImage` option and specify a different image inside the `baseFolder` directory.

Expand Down
34 changes: 32 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,34 @@ export = ResembleHelper;
* Resemble.js helper class for CodeceptJS, this allows screen comparison
* @author Puneet Kala
*/
declare class Endpoint {
/**
* Constructs a new endpoint given an endpoint URL.
*/
constructor(url: string);

/**
* The host portion of the endpoint including the port, e.g., example.com:80.
*/
host: string;
/**
* The host portion of the endpoint, e.g., example.com.
*/
hostname: string;
/**
* The full URL of the endpoint.
*/
href: string;
/**
* The port of the endpoint.
*/
port: number;
/**
* The protocol (http or https) of the endpoint URL.
*/
protocol: string;
}

declare class ResembleHelper {
constructor(config: any);
baseFolder: any;
Expand Down Expand Up @@ -57,9 +85,10 @@ declare class ResembleHelper {
* @param bucketName
* @param baseImage
* @param options
* @param {string | Endpoint } [endpoint]
* @returns {Promise<void>}
*/
_upload(accessKeyId: any, secretAccessKey: any, region: any, bucketName: any, baseImage: any, options: any): Promise<void>;
_upload(accessKeyId: any, secretAccessKey: any, region: any, bucketName: any, baseImage: any, options: any, endpoint?: string | Endpoint): Promise<void>;
/**
* This method downloads base images from specified bucket into the base folder as mentioned in config file.
* @param accessKeyId
Expand All @@ -68,9 +97,10 @@ declare class ResembleHelper {
* @param bucketName
* @param baseImage
* @param options
* @param {string | Endpoint } [endpoint]
* @returns {Promise<void>}
*/
_download(accessKeyId: any, secretAccessKey: any, region: any, bucketName: any, baseImage: any, options: any): Promise<void>;
_download(accessKeyId: any, secretAccessKey: any, region: any, bucketName: any, baseImage: any, options: any, endpoint?: string | Endpoint): Promise<void>;
/**
* Check Visual Difference for Base and Screenshot Image
* @param baseImage Name of the Base Image (Base Image path is taken from Configuration)
Expand Down
16 changes: 10 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,17 @@ class ResembleHelper extends Helper {
* @param bucketName
* @param baseImage
* @param options
* @param {string | Endpoint } [endpoint]
* @returns {Promise<void>}
*/

async _upload(accessKeyId, secretAccessKey, region, bucketName, baseImage, options) {
async _upload(accessKeyId, secretAccessKey, region, bucketName, baseImage, options, endpoint) {
console.log("Starting Upload... ");
const s3 = new AWS.S3({
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
region: region
region: region,
endpoint: endpoint
});
fs.readFile(this._getActualImagePath(baseImage), (err, data) => {
if (err) throw err;
Expand Down Expand Up @@ -279,16 +281,18 @@ class ResembleHelper extends Helper {
* @param bucketName
* @param baseImage
* @param options
* @param {string | Endpoint } [endpoint]
* @returns {Promise<void>}
*/

_download(accessKeyId, secretAccessKey, region, bucketName, baseImage, options) {
_download(accessKeyId, secretAccessKey, region, bucketName, baseImage, options, endpoint) {
console.log("Starting Download...");
const baseImageName = this._getBaseImageName(baseImage, options);
const s3 = new AWS.S3({
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
region: region
region: region,
endpoint: endpoint
});
const params = {
Bucket: bucketName,
Expand Down Expand Up @@ -337,7 +341,7 @@ class ResembleHelper extends Helper {
if (this._getPrepareBaseImage(options)) {
await this._prepareBaseImage(baseImage, options);
} else if (awsC !== undefined) {
await this._download(awsC.accessKeyId, awsC.secretAccessKey, awsC.region, awsC.bucketName, baseImage, options);
await this._download(awsC.accessKeyId, awsC.secretAccessKey, awsC.region, awsC.bucketName, baseImage, options, awsC.endpoint);
}

if (selector) {
Expand All @@ -347,7 +351,7 @@ class ResembleHelper extends Helper {
this._addAttachment(baseImage, misMatch, options);
this._addMochaContext(baseImage, misMatch, options);
if (awsC !== undefined) {
await this._upload(awsC.accessKeyId, awsC.secretAccessKey, awsC.region, awsC.bucketName, baseImage, options)
await this._upload(awsC.accessKeyId, awsC.secretAccessKey, awsC.region, awsC.bucketName, baseImage, options, awsC.endpoint)
}

this.debug("MisMatch Percentage Calculated is " + misMatch + " for baseline " + baseImage);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codeceptjs-resemblehelper",
"version": "1.9.5",
"version": "1.9.6",
"description": "Resemble Js helper for CodeceptJS, with Support for Playwright, Webdriver, TestCafe, Puppeteer & Appium",
"repository": {
"type": "git",
Expand Down