diff --git a/README.md b/README.md index 4aba0a9..333cc20 100644 --- a/README.md +++ b/README.md @@ -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": "", + "diffFolder": "", + "aws": { + "accessKeyId" : "", + "secretAccessKey": "", + "region": "", + "bucketName": "", + "endpoint": "" + } + } + } +} +``` + ### 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. diff --git a/index.d.ts b/index.d.ts index 612333c..491160a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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; @@ -58,9 +86,10 @@ declare class ResembleHelper { * @param bucketName * @param baseImage * @param options + * @param {string | Endpoint } [endpoint] * @returns {Promise} */ - _upload(accessKeyId: any, secretAccessKey: any, region: any, bucketName: any, baseImage: any, options: any): Promise; + _upload(accessKeyId: any, secretAccessKey: any, region: any, bucketName: any, baseImage: any, options: any, endpoint?: string | Endpoint): Promise; /** * This method downloads base images from specified bucket into the base folder as mentioned in config file. * @param accessKeyId @@ -69,9 +98,10 @@ declare class ResembleHelper { * @param bucketName * @param baseImage * @param options + * @param {string | Endpoint } [endpoint] * @returns {Promise} */ - _download(accessKeyId: any, secretAccessKey: any, region: any, bucketName: any, baseImage: any, options: any): Promise; + _download(accessKeyId: any, secretAccessKey: any, region: any, bucketName: any, baseImage: any, options: any, endpoint?: string | Endpoint): Promise; /** * Check Visual Difference for Base and Screenshot Image * @param baseImage Name of the Base Image (Base Image path is taken from Configuration) diff --git a/index.js b/index.js index 03a8778..02c76ca 100644 --- a/index.js +++ b/index.js @@ -208,15 +208,17 @@ class ResembleHelper extends Helper { * @param bucketName * @param baseImage * @param options + * @param {string | Endpoint } [endpoint] * @returns {Promise} */ - 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; @@ -279,16 +281,18 @@ class ResembleHelper extends Helper { * @param bucketName * @param baseImage * @param options + * @param {string | Endpoint } [endpoint] * @returns {Promise} */ - _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, @@ -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); } // BoundingBox for Playwright not necessary @@ -348,7 +352,7 @@ class ResembleHelper extends Helper { await this._addAttachment(baseImage, misMatch, options); await 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);