Skip to content

Commit 1292273

Browse files
authored
Merge pull request #124 from codeceptjs/1.9.7
1.9.7 Release Merge
2 parents 52afc96 + 03acb59 commit 1292273

File tree

4 files changed

+77
-19
lines changed

4 files changed

+77
-19
lines changed

README.md

Lines changed: 22 additions & 0 deletions
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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,50 @@ 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;
937
diffFolder: any;
1038
screenshotFolder: string;
1139
prepareBaseImage: any;
1240
resolvePath(folderPath: any): any;
41+
_resolveRelativePath(folderPath: any): any;
1342
/**
1443
* Compare Images
1544
*
1645
* @param image
1746
* @param options
1847
* @returns {Promise<resolve | reject>}
1948
*/
20-
_compareImages(image: any, options: any): Promise<any | any>;
49+
_compareImages(image: any, options: any): Promise<resolve | reject>;
2150
/**
2251
*
2352
* @param image
@@ -57,9 +86,10 @@ declare class ResembleHelper {
5786
* @param bucketName
5887
* @param baseImage
5988
* @param options
89+
* @param {string | Endpoint } [endpoint]
6090
* @returns {Promise<void>}
6191
*/
62-
_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>;
6393
/**
6494
* This method downloads base images from specified bucket into the base folder as mentioned in config file.
6595
* @param accessKeyId
@@ -68,9 +98,10 @@ declare class ResembleHelper {
6898
* @param bucketName
6999
* @param baseImage
70100
* @param options
101+
* @param {string | Endpoint } [endpoint]
71102
* @returns {Promise<void>}
72103
*/
73-
_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>;
74105
/**
75106
* Check Visual Difference for Base and Screenshot Image
76107
* @param baseImage Name of the Base Image (Base Image path is taken from Configuration)

index.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ResembleHelper extends Helper {
4141
absolutePathOfReportFolder = Container.mocha().options.reporterOptions.reportDir;
4242
}
4343
// support mocha-multi-reporters
44-
if (Container.mocha() && typeof Container.mocha().options.reporterOptions.mochawesomeReporterOptions.reportDir !== 'undefined') {
44+
if (Container.mocha() && typeof Container.mocha().options.reporterOptions.mochawesomeReporterOptions?.reportDir !== 'undefined') {
4545
absolutePathOfReportFolder = Container.mocha().options.reporterOptions.mochawesomeReporterOptions.reportDir;
4646
}
4747
return path.relative(absolutePathOfReportFolder, absolutePathOfImage);
@@ -78,7 +78,7 @@ class ResembleHelper extends Helper {
7878

7979
return new Promise((resolve, reject) => {
8080

81-
if (options.outputSettings) {
81+
if (!options.outputSettings) {
8282
options.outputSettings = {};
8383
}
8484
if (typeof options.needsSameDimension === 'undefined') {
@@ -93,7 +93,7 @@ class ResembleHelper extends Helper {
9393
this.debug("Tolerance Level Provided " + options.tolerance);
9494
const tolerance = options.tolerance;
9595

96-
resemble.compare(baseImage, actualImage, options, (err, data) => {
96+
resemble.compare(actualImage, baseImage, options, (err, data) => {
9797
if (err) {
9898
reject(err);
9999
} else {
@@ -191,11 +191,11 @@ class ResembleHelper extends Helper {
191191

192192
if (mocha !== undefined && misMatch >= options.tolerance) {
193193
await mocha.addMochawesomeContext("Base Image");
194-
await mocha.addMochawesomeContext(this.resolveImagePathRelativeFromReport(this._getBaseImagePath(baseImage, options)));
194+
await mocha.addMochawesomeContext(this._resolveRelativePath(this._getBaseImagePath(baseImage, options)));
195195
await mocha.addMochawesomeContext("ScreenShot Image");
196-
await mocha.addMochawesomeContext(this.resolveImagePathRelativeFromReport(this._getActualImagePath(baseImage)));
196+
await mocha.addMochawesomeContext(this._resolveRelativePath(this._getActualImagePath(baseImage)));
197197
await mocha.addMochawesomeContext("Diff Image");
198-
await mocha.addMochawesomeContext(this.resolveImagePathRelativeFromReport(this._getDiffImagePath(baseImage)));
198+
await mocha.addMochawesomeContext(this._resolveRelativePath(this._getDiffImagePath(baseImage)));
199199
}
200200
}
201201

@@ -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,17 +341,18 @@ 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

343-
if (selector) {
347+
// BoundingBox for Playwright not necessary
348+
if (selector && !this.helpers['Playwright']) {
344349
options.boundingBox = await this._getBoundingBox(selector);
345350
}
346351
const misMatch = await this._fetchMisMatchPercentage(baseImage, options);
347-
this._addAttachment(baseImage, misMatch, options);
348-
this._addMochaContext(baseImage, misMatch, options);
352+
await this._addAttachment(baseImage, misMatch, options);
353+
await this._addMochaContext(baseImage, misMatch, options);
349354
if (awsC !== undefined) {
350-
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)
351356
}
352357

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codeceptjs-resemblehelper",
3-
"version": "1.9.6",
3+
"version": "1.9.7",
44
"description": "Resemble Js helper for CodeceptJS, with Support for Playwright, Webdriver, TestCafe, Puppeteer & Appium",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)