@argos-ci/puppeteer 0.0.1 → 0.0.3
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/README.md +12 -41
- package/index.d.ts +11 -5
- package/index.js +57 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,49 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://argos-ci.com/?utm_source=github&utm_medium=logo" target="_blank">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/argos-ci/argos/main/resources/logos/logo-github-readme.png" alt="Argos" width="300" height="61">
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
_Argos is a visual testing solution that fits in your workflow to avoid visual regression. Takes screenshots on each commit and be notified if something changes._
|
|
8
|
+
|
|
9
|
+
# Official Argos Puppeteer integration
|
|
4
10
|
|
|
5
11
|
[](https://www.npmjs.com/package/@argos-ci/puppeteer)
|
|
6
12
|
[](https://www.npmjs.com/package/@argos-ci/puppeteer)
|
|
7
13
|
[](https://www.npmjs.com/package/@argos-ci/puppeteer)
|
|
8
14
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
```sh
|
|
12
|
-
npm install --save-dev @argos-ci/puppeteer
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Usage
|
|
16
|
-
|
|
17
|
-
Stabilizes the UI before taking a screenshot.
|
|
18
|
-
|
|
19
|
-
`argosScreenshot(page, name[, options])`
|
|
20
|
-
|
|
21
|
-
- `page` - A `puppeteer` page instance
|
|
22
|
-
- `name` - The screenshot name; must be unique
|
|
23
|
-
- `options` - See [Page.screenshot command options](https://pptr.dev/next/api/puppeteer.page.screenshot/)
|
|
24
|
-
|
|
25
|
-
```js
|
|
26
|
-
describe("Integration test with visual testing", () => {
|
|
27
|
-
it("Loads the homepage", async () => {
|
|
28
|
-
const browser = await puppeteer.launch();
|
|
29
|
-
const page = await browser.newPage();
|
|
30
|
-
await page.goto(TEST_URL);
|
|
31
|
-
await argosScreenshot(page, this.test.fullTitle());
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Helper attributes
|
|
37
|
-
|
|
38
|
-
The `data-visual-test` attributes allow you to control how elements behave in the Argos screenshot.
|
|
39
|
-
|
|
40
|
-
It is often used to hide changing element like dates.
|
|
15
|
+
Visit [argos-ci.com/docs/puppeteer](https://argos-ci.com/docs/puppeteer) for guides, API and more.
|
|
41
16
|
|
|
42
|
-
|
|
43
|
-
- `[data-visual-test="removed"]` - Remove the element (`display: none`)
|
|
44
|
-
- `[data-visual-test="blackout"]` - Blacked out the element
|
|
17
|
+
## Links
|
|
45
18
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
<div id="clock" data-visual-test="transparent">...</div>
|
|
49
|
-
```
|
|
19
|
+
- [Official SDK Docs](https://argos-ci.com/docs/)
|
|
20
|
+
- [Discord](https://argos-ci.com/discord)
|
package/index.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import type { Page, ScreenshotOptions } from "puppeteer";
|
|
1
|
+
import type { Page, ScreenshotOptions, ElementHandle } from "puppeteer";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
export interface ArgosScreenshotOptions
|
|
4
|
+
extends Omit<
|
|
5
|
+
ScreenshotOptions,
|
|
6
|
+
"encoding" | "type" | "omitBackground" | "path"
|
|
7
|
+
> {
|
|
8
|
+
/**
|
|
9
|
+
* ElementHandle or string selector of the element to take a screenshot of.
|
|
10
|
+
*/
|
|
11
|
+
element?: string | ElementHandle;
|
|
12
|
+
}
|
|
7
13
|
|
|
8
14
|
/**
|
|
9
15
|
* Stabilize the UI and takes a screenshot of the application under test.
|
package/index.js
CHANGED
|
@@ -38,27 +38,74 @@ async function ensureNoBusy() {
|
|
|
38
38
|
);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Wait for all fonts to be loaded.
|
|
43
|
+
*/
|
|
44
|
+
function waitForFonts() {
|
|
43
45
|
return document.fonts.status === "loaded";
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Wait for all images to be loaded.
|
|
50
|
+
*/
|
|
51
|
+
async function waitForImages() {
|
|
52
|
+
return Promise.all(
|
|
53
|
+
Array.from(document.images)
|
|
54
|
+
.filter((img) => !img.complete)
|
|
55
|
+
.map(
|
|
56
|
+
(img) =>
|
|
57
|
+
new Promise((resolve) => {
|
|
58
|
+
img.onload = img.onerror = resolve;
|
|
59
|
+
})
|
|
60
|
+
)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Disable spellcheck to avoid red underlines
|
|
66
|
+
*/
|
|
67
|
+
function disableSpellCheck() {
|
|
68
|
+
const query =
|
|
69
|
+
"[contenteditable]:not([contenteditable=false]):not([spellcheck=false]), input:not([spellcheck=false]), textarea:not([spellcheck=false])";
|
|
70
|
+
const inputs = document.querySelectorAll(query);
|
|
71
|
+
inputs.forEach((input) => input.setAttribute("spellcheck", "false"));
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function argosScreenshot(
|
|
76
|
+
page,
|
|
77
|
+
name,
|
|
78
|
+
{ element = page, ...options } = {}
|
|
79
|
+
) {
|
|
47
80
|
if (!page) throw new Error("A Puppeteer `page` object is required.");
|
|
48
81
|
if (!name) throw new Error("The `name` argument is required.");
|
|
49
82
|
|
|
50
|
-
|
|
83
|
+
if (typeof element === "string") {
|
|
84
|
+
await page.waitForSelector(element);
|
|
85
|
+
element = await page.$(element);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const directory = resolve(process.cwd(), "screenshots/argos");
|
|
89
|
+
|
|
90
|
+
const [resolvedElement] = await Promise.all([
|
|
91
|
+
(async () => {
|
|
92
|
+
if (typeof element === "string") {
|
|
93
|
+
await page.waitForSelector(element);
|
|
94
|
+
return page.$(element);
|
|
95
|
+
}
|
|
96
|
+
return element;
|
|
97
|
+
})(),
|
|
98
|
+
mkdirp(directory),
|
|
51
99
|
page.addStyleTag({ content: GLOBAL_STYLES }),
|
|
52
100
|
page.waitForFunction(ensureNoBusy),
|
|
53
|
-
page.waitForFunction(
|
|
101
|
+
page.waitForFunction(waitForFonts),
|
|
102
|
+
page.waitForFunction(waitForImages),
|
|
103
|
+
page.waitForFunction(disableSpellCheck),
|
|
54
104
|
]);
|
|
55
105
|
|
|
56
|
-
|
|
57
|
-
await mkdirp(directory);
|
|
58
|
-
await page.screenshot({
|
|
106
|
+
await resolvedElement.screenshot({
|
|
59
107
|
path: resolve(directory, `${name}.png`),
|
|
60
108
|
type: "png",
|
|
61
|
-
|
|
62
|
-
clip,
|
|
109
|
+
...options,
|
|
63
110
|
});
|
|
64
111
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@argos-ci/puppeteer",
|
|
3
3
|
"description": "Visual testing solution to avoid visual regression. Puppeteer commands and utilities for Argos visual testing.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"author": "Smooth Code",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "github:argos-ci/argos-puppeteer",
|