@argos-ci/webdriverio 0.6.24 → 0.6.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/{index.d.ts → index.d.mts} +24 -20
- package/dist/index.mjs +77 -0
- package/package.json +14 -14
- package/dist/index.js +0 -76
package/dist/index.cjs
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
1
2
|
type ArgosScreenshotOptions = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Specify ares that should be masked when the screenshot is taken.
|
|
5
|
+
* Masked elements will be overlaid with a pink box #FF00FF (customized by maskColor)
|
|
6
|
+
* that completely covers its bounding box.
|
|
7
|
+
*/
|
|
8
|
+
mask?: {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
}[];
|
|
14
|
+
/**
|
|
15
|
+
* Specify the color of the overlay box for masked elements, in CSS color format.
|
|
16
|
+
* Default color is pink #FF00FF.
|
|
17
|
+
* @default "#FF00FF"
|
|
18
|
+
*/
|
|
19
|
+
maskColor?: string;
|
|
19
20
|
};
|
|
20
21
|
/**
|
|
21
22
|
* Take a screenshot of the current page, optionally masking certain areas.
|
|
@@ -30,6 +31,9 @@ type ArgosScreenshotOptions = {
|
|
|
30
31
|
* Specify the color of the overlay box for masked elements, in CSS color format.
|
|
31
32
|
* Default color is pink #FF00FF.
|
|
32
33
|
*/
|
|
33
|
-
declare function argosScreenshot(browser: WebdriverIO.Browser, name: string, {
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
declare function argosScreenshot(browser: WebdriverIO.Browser, name: string, {
|
|
35
|
+
mask,
|
|
36
|
+
maskColor
|
|
37
|
+
}?: ArgosScreenshotOptions): Promise<Buffer<ArrayBufferLike>>;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { ArgosScreenshotOptions, argosScreenshot };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import sharp from "sharp";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { mkdir } from "node:fs/promises";
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
async function createMask(dimensions, areas, maskColor) {
|
|
6
|
+
let mask = sharp({ create: {
|
|
7
|
+
width: dimensions.width,
|
|
8
|
+
height: dimensions.height,
|
|
9
|
+
channels: 4,
|
|
10
|
+
background: {
|
|
11
|
+
r: 0,
|
|
12
|
+
g: 0,
|
|
13
|
+
b: 0,
|
|
14
|
+
alpha: 0
|
|
15
|
+
}
|
|
16
|
+
} });
|
|
17
|
+
const areasImages = areas.map((coords) => ({
|
|
18
|
+
input: Buffer.from("<svg><rect x=\"0\" y=\"0\" width=\"" + coords.width + "\" height=\"" + coords.height + `" fill="${maskColor}"/></svg>`),
|
|
19
|
+
top: coords.y,
|
|
20
|
+
left: coords.x
|
|
21
|
+
}));
|
|
22
|
+
mask = mask.composite(areasImages);
|
|
23
|
+
return mask.png().toBuffer();
|
|
24
|
+
}
|
|
25
|
+
async function applyMask(image, mask) {
|
|
26
|
+
try {
|
|
27
|
+
return await sharp(image).composite([{
|
|
28
|
+
input: mask,
|
|
29
|
+
blend: "over"
|
|
30
|
+
}]).png().toBuffer();
|
|
31
|
+
} catch (err) {
|
|
32
|
+
throw new Error("Error applying mask", { cause: err });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function getImageDimensions(buffer) {
|
|
36
|
+
try {
|
|
37
|
+
const { width, height } = await sharp(buffer).metadata();
|
|
38
|
+
if (!width || !height) throw new Error("Dimensions not found.");
|
|
39
|
+
return {
|
|
40
|
+
width,
|
|
41
|
+
height
|
|
42
|
+
};
|
|
43
|
+
} catch (err) {
|
|
44
|
+
throw new Error("Error getting image dimensions", { cause: err });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async function getScreenshotPath(name) {
|
|
48
|
+
if (name.endsWith(".png")) return name;
|
|
49
|
+
const screenshotFolder = resolve(process.cwd(), "screenshots/argos");
|
|
50
|
+
await mkdir(screenshotFolder, { recursive: true });
|
|
51
|
+
return resolve(screenshotFolder, name + ".png");
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Take a screenshot of the current page, optionally masking certain areas.
|
|
55
|
+
* @param browser A WebdriverIO `browser` object.
|
|
56
|
+
* @param name The name of the screenshot or the full path to the screenshot.
|
|
57
|
+
* @param options Options to customize the screenshot.
|
|
58
|
+
* @param options.mask
|
|
59
|
+
* Specify ares that should be masked when the screenshot is taken.
|
|
60
|
+
* Masked elements will be overlaid with a pink box #FF00FF (customized by maskColor)
|
|
61
|
+
* that completely covers its bounding box.
|
|
62
|
+
* @param options.maskColor
|
|
63
|
+
* Specify the color of the overlay box for masked elements, in CSS color format.
|
|
64
|
+
* Default color is pink #FF00FF.
|
|
65
|
+
*/
|
|
66
|
+
async function argosScreenshot(browser, name, { mask, maskColor = "#FF00FF" } = {}) {
|
|
67
|
+
if (!browser) throw new Error("A WebdriverIO `browser` object is required.");
|
|
68
|
+
if (!name) throw new Error("The `name` argument is required.");
|
|
69
|
+
const screenshotPath = await getScreenshotPath(name);
|
|
70
|
+
const imageBuffer = await browser.saveScreenshot(screenshotPath);
|
|
71
|
+
if (!mask) return imageBuffer;
|
|
72
|
+
const maskedBuffer = await applyMask(imageBuffer, await createMask(await getImageDimensions(imageBuffer), mask, maskColor));
|
|
73
|
+
await sharp(maskedBuffer).toFile(screenshotPath);
|
|
74
|
+
return maskedBuffer;
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
export { argosScreenshot };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@argos-ci/webdriverio",
|
|
3
3
|
"description": "WebdriverIO SDK for visual testing with Argos.",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.25",
|
|
5
5
|
"author": "Smooth Code",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"access": "public"
|
|
27
27
|
},
|
|
28
28
|
"type": "module",
|
|
29
|
-
"types": "./dist/index.d.
|
|
29
|
+
"types": "./dist/index.d.mts",
|
|
30
30
|
"exports": {
|
|
31
31
|
".": {
|
|
32
|
-
"types": "./dist/index.d.
|
|
33
|
-
"import": "./dist/index.
|
|
32
|
+
"types": "./dist/index.d.mts",
|
|
33
|
+
"import": "./dist/index.mjs",
|
|
34
34
|
"require": "./dist/index.cjs",
|
|
35
35
|
"default": "./dist/index.cjs"
|
|
36
36
|
},
|
|
@@ -46,18 +46,18 @@
|
|
|
46
46
|
"sharp": "^0.34.5"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@argos-ci/cli": "4.1.
|
|
50
|
-
"@wdio/cli": "^9.
|
|
51
|
-
"@wdio/globals": "^9.
|
|
52
|
-
"@wdio/local-runner": "^9.
|
|
53
|
-
"@wdio/mocha-framework": "^9.
|
|
54
|
-
"@wdio/spec-reporter": "^9.
|
|
55
|
-
"@wdio/types": "^9.
|
|
49
|
+
"@argos-ci/cli": "4.1.3",
|
|
50
|
+
"@wdio/cli": "^9.27.0",
|
|
51
|
+
"@wdio/globals": "^9.27.0",
|
|
52
|
+
"@wdio/local-runner": "^9.27.0",
|
|
53
|
+
"@wdio/mocha-framework": "^9.27.0",
|
|
54
|
+
"@wdio/spec-reporter": "^9.27.0",
|
|
55
|
+
"@wdio/types": "^9.27.0",
|
|
56
56
|
"tsx": "^4.21.0",
|
|
57
|
-
"webdriverio": "^9.
|
|
57
|
+
"webdriverio": "^9.27.0"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
|
-
"build": "
|
|
60
|
+
"build": "tsdown && cp ./src/index.cjs ./dist",
|
|
61
61
|
"test-e2e": "wdio run ./wdio.conf.ts",
|
|
62
62
|
"argos-upload": "pnpm exec argos upload screenshots --build-name \"argos-webdriverio-e2e-node-$NODE_VERSION-$OS\"",
|
|
63
63
|
"e2e": "pnpm run test-e2e && pnpm run argos-upload",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"check-format": "prettier --check --ignore-unknown --ignore-path=../../.gitignore --ignore-path=../../.prettierignore .",
|
|
66
66
|
"lint": "eslint ."
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "b49d186d5eb6e1338982a4cd5c3cb29e6cb0b7af"
|
|
69
69
|
}
|
package/dist/index.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import sharp from "sharp";
|
|
3
|
-
import { resolve } from "path";
|
|
4
|
-
import { mkdir } from "fs/promises";
|
|
5
|
-
async function createMask(dimensions, areas, maskColor) {
|
|
6
|
-
let mask = sharp({
|
|
7
|
-
create: {
|
|
8
|
-
width: dimensions.width,
|
|
9
|
-
height: dimensions.height,
|
|
10
|
-
channels: 4,
|
|
11
|
-
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
const areasImages = areas.map((coords) => ({
|
|
15
|
-
input: Buffer.from(
|
|
16
|
-
'<svg><rect x="0" y="0" width="' + coords.width + '" height="' + coords.height + `" fill="${maskColor}"/></svg>`
|
|
17
|
-
),
|
|
18
|
-
top: coords.y,
|
|
19
|
-
left: coords.x
|
|
20
|
-
}));
|
|
21
|
-
mask = mask.composite(areasImages);
|
|
22
|
-
return mask.png().toBuffer();
|
|
23
|
-
}
|
|
24
|
-
async function applyMask(image, mask) {
|
|
25
|
-
try {
|
|
26
|
-
return await sharp(image).composite([
|
|
27
|
-
{
|
|
28
|
-
input: mask,
|
|
29
|
-
blend: "over"
|
|
30
|
-
}
|
|
31
|
-
]).png().toBuffer();
|
|
32
|
-
} catch (err) {
|
|
33
|
-
throw new Error("Error applying mask", { cause: err });
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
async function getImageDimensions(buffer) {
|
|
37
|
-
try {
|
|
38
|
-
const imageInfo = await sharp(buffer).metadata();
|
|
39
|
-
const { width, height } = imageInfo;
|
|
40
|
-
if (!width || !height) {
|
|
41
|
-
throw new Error("Dimensions not found.");
|
|
42
|
-
}
|
|
43
|
-
return { width, height };
|
|
44
|
-
} catch (err) {
|
|
45
|
-
throw new Error("Error getting image dimensions", { cause: err });
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
async function getScreenshotPath(name) {
|
|
49
|
-
if (name.endsWith(".png")) {
|
|
50
|
-
return name;
|
|
51
|
-
}
|
|
52
|
-
const screenshotFolder = resolve(process.cwd(), "screenshots/argos");
|
|
53
|
-
await mkdir(screenshotFolder, { recursive: true });
|
|
54
|
-
return resolve(screenshotFolder, name + ".png");
|
|
55
|
-
}
|
|
56
|
-
async function argosScreenshot(browser, name, { mask, maskColor = "#FF00FF" } = {}) {
|
|
57
|
-
if (!browser) {
|
|
58
|
-
throw new Error("A WebdriverIO `browser` object is required.");
|
|
59
|
-
}
|
|
60
|
-
if (!name) {
|
|
61
|
-
throw new Error("The `name` argument is required.");
|
|
62
|
-
}
|
|
63
|
-
const screenshotPath = await getScreenshotPath(name);
|
|
64
|
-
const imageBuffer = await browser.saveScreenshot(screenshotPath);
|
|
65
|
-
if (!mask) {
|
|
66
|
-
return imageBuffer;
|
|
67
|
-
}
|
|
68
|
-
const dimensions = await getImageDimensions(imageBuffer);
|
|
69
|
-
const maskBuffer = await createMask(dimensions, mask, maskColor);
|
|
70
|
-
const maskedBuffer = await applyMask(imageBuffer, maskBuffer);
|
|
71
|
-
await sharp(maskedBuffer).toFile(screenshotPath);
|
|
72
|
-
return maskedBuffer;
|
|
73
|
-
}
|
|
74
|
-
export {
|
|
75
|
-
argosScreenshot
|
|
76
|
-
};
|