Skip to content

Commit 26419e4

Browse files
authored
Naive implementation of using different endpoints in aws-sdk (#107)
1 parent e0fb25d commit 26419e4

File tree

3 files changed

+64
-8
lines changed

3 files changed

+64
-8
lines changed

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,28 @@ The resultant output image will be uploaded in a folder named "*output*" and dif
184184
If the `prepareBaseImage` option is marked `true`, then the generated base image will be uploaded to a folder named "*base*" in the S3 bucket.
185185
> 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.
186186
187+
### Other S3 Providers
188+
The same configuration as above, but with *endpoint* field:
189+
190+
```json
191+
{
192+
"helpers": {
193+
"ResembleHelper" : {
194+
"require": "codeceptjs-resemblehelper",
195+
"baseFolder": "<location of base folder>",
196+
"diffFolder": "<location of diff folder>",
197+
"aws": {
198+
"accessKeyId" : "<Your AccessKeyId>",
199+
"secretAccessKey": "<Your secretAccessKey>",
200+
"region": "<Region of Bucket>",
201+
"bucketName": "<Bucket Name>",
202+
"endpoint": "<Endpoint of Bucket>"
203+
}
204+
}
205+
}
206+
}
207+
```
208+
187209
### Compare with custom image
188210
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.
189211

index.d.ts

+32-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,34 @@ export = ResembleHelper;
33
* Resemble.js helper class for CodeceptJS, this allows screen comparison
44
* @author Puneet Kala
55
*/
6+
declare class Endpoint {
7+
/**
8+
* Constructs a new endpoint given an endpoint URL.
9+
*/
10+
constructor(url: string);
11+
12+
/**
13+
* The host portion of the endpoint including the port, e.g., example.com:80.
14+
*/
15+
host: string;
16+
/**
17+
* The host portion of the endpoint, e.g., example.com.
18+
*/
19+
hostname: string;
20+
/**
21+
* The full URL of the endpoint.
22+
*/
23+
href: string;
24+
/**
25+
* The port of the endpoint.
26+
*/
27+
port: number;
28+
/**
29+
* The protocol (http or https) of the endpoint URL.
30+
*/
31+
protocol: string;
32+
}
33+
634
declare class ResembleHelper {
735
constructor(config: any);
836
baseFolder: any;
@@ -58,9 +86,10 @@ declare class ResembleHelper {
5886
* @param bucketName
5987
* @param baseImage
6088
* @param options
89+
* @param {string | Endpoint } [endpoint]
6190
* @returns {Promise<void>}
6291
*/
63-
_upload(accessKeyId: any, secretAccessKey: any, region: any, bucketName: any, baseImage: any, options: any): Promise<void>;
92+
_upload(accessKeyId: any, secretAccessKey: any, region: any, bucketName: any, baseImage: any, options: any, endpoint?: string | Endpoint): Promise<void>;
6493
/**
6594
* This method downloads base images from specified bucket into the base folder as mentioned in config file.
6695
* @param accessKeyId
@@ -69,9 +98,10 @@ declare class ResembleHelper {
6998
* @param bucketName
7099
* @param baseImage
71100
* @param options
101+
* @param {string | Endpoint } [endpoint]
72102
* @returns {Promise<void>}
73103
*/
74-
_download(accessKeyId: any, secretAccessKey: any, region: any, bucketName: any, baseImage: any, options: any): Promise<void>;
104+
_download(accessKeyId: any, secretAccessKey: any, region: any, bucketName: any, baseImage: any, options: any, endpoint?: string | Endpoint): Promise<void>;
75105
/**
76106
* Check Visual Difference for Base and Screenshot Image
77107
* @param baseImage Name of the Base Image (Base Image path is taken from Configuration)

index.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,17 @@ class ResembleHelper extends Helper {
208208
* @param bucketName
209209
* @param baseImage
210210
* @param options
211+
* @param {string | Endpoint } [endpoint]
211212
* @returns {Promise<void>}
212213
*/
213214

214-
async _upload(accessKeyId, secretAccessKey, region, bucketName, baseImage, options) {
215+
async _upload(accessKeyId, secretAccessKey, region, bucketName, baseImage, options, endpoint) {
215216
console.log("Starting Upload... ");
216217
const s3 = new AWS.S3({
217218
accessKeyId: accessKeyId,
218219
secretAccessKey: secretAccessKey,
219-
region: region
220+
region: region,
221+
endpoint: endpoint
220222
});
221223
fs.readFile(this._getActualImagePath(baseImage), (err, data) => {
222224
if (err) throw err;
@@ -279,16 +281,18 @@ class ResembleHelper extends Helper {
279281
* @param bucketName
280282
* @param baseImage
281283
* @param options
284+
* @param {string | Endpoint } [endpoint]
282285
* @returns {Promise<void>}
283286
*/
284287

285-
_download(accessKeyId, secretAccessKey, region, bucketName, baseImage, options) {
288+
_download(accessKeyId, secretAccessKey, region, bucketName, baseImage, options, endpoint) {
286289
console.log("Starting Download...");
287290
const baseImageName = this._getBaseImageName(baseImage, options);
288291
const s3 = new AWS.S3({
289292
accessKeyId: accessKeyId,
290293
secretAccessKey: secretAccessKey,
291-
region: region
294+
region: region,
295+
endpoint: endpoint
292296
});
293297
const params = {
294298
Bucket: bucketName,
@@ -337,7 +341,7 @@ class ResembleHelper extends Helper {
337341
if (this._getPrepareBaseImage(options)) {
338342
await this._prepareBaseImage(baseImage, options);
339343
} else if (awsC !== undefined) {
340-
await this._download(awsC.accessKeyId, awsC.secretAccessKey, awsC.region, awsC.bucketName, baseImage, options);
344+
await this._download(awsC.accessKeyId, awsC.secretAccessKey, awsC.region, awsC.bucketName, baseImage, options, awsC.endpoint);
341345
}
342346

343347
// BoundingBox for Playwright not necessary
@@ -348,7 +352,7 @@ class ResembleHelper extends Helper {
348352
await this._addAttachment(baseImage, misMatch, options);
349353
await this._addMochaContext(baseImage, misMatch, options);
350354
if (awsC !== undefined) {
351-
await this._upload(awsC.accessKeyId, awsC.secretAccessKey, awsC.region, awsC.bucketName, baseImage, options)
355+
await this._upload(awsC.accessKeyId, awsC.secretAccessKey, awsC.region, awsC.bucketName, baseImage, options, awsC.endpoint)
352356
}
353357

354358
this.debug("MisMatch Percentage Calculated is " + misMatch + " for baseline " + baseImage);

0 commit comments

Comments
 (0)