@argos-ci/puppeteer 0.0.1
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/LICENSE +7 -0
- package/README.md +49 -0
- package/index.cjs +6 -0
- package/index.d.ts +18 -0
- package/index.js +64 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2022 Smooth Code
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# @argos-ci/puppeteer
|
|
2
|
+
|
|
3
|
+
[Puppeteer](https://pptr.dev/) commands and utilities for [Argos](https://argos-ci.com) visual testing.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@argos-ci/puppeteer)
|
|
6
|
+
[](https://www.npmjs.com/package/@argos-ci/puppeteer)
|
|
7
|
+
[](https://www.npmjs.com/package/@argos-ci/puppeteer)
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
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.
|
|
41
|
+
|
|
42
|
+
- `[data-visual-test="transparent"]` - Make the element transparent (`opacity: 0`)
|
|
43
|
+
- `[data-visual-test="removed"]` - Remove the element (`display: none`)
|
|
44
|
+
- `[data-visual-test="blackout"]` - Blacked out the element
|
|
45
|
+
|
|
46
|
+
```html
|
|
47
|
+
<!-- Hide a div from a screenshot -->
|
|
48
|
+
<div id="clock" data-visual-test="transparent">...</div>
|
|
49
|
+
```
|
package/index.cjs
ADDED
package/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Page, ScreenshotOptions } from "puppeteer";
|
|
2
|
+
|
|
3
|
+
export type ArgosScreenshotOptions = Omit<
|
|
4
|
+
ScreenshotOptions,
|
|
5
|
+
"encoding" | "type" | "omitBackground" | "path"
|
|
6
|
+
>;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Stabilize the UI and takes a screenshot of the application under test.
|
|
10
|
+
* @example
|
|
11
|
+
* await argosScreenshot(page, "my-screenshot")
|
|
12
|
+
* await argosScreenshot(page, "my-screenshot", { fullPage: true })
|
|
13
|
+
*/
|
|
14
|
+
export function argosScreenshot(
|
|
15
|
+
page: Page,
|
|
16
|
+
name: string,
|
|
17
|
+
options?: ArgosScreenshotOptions
|
|
18
|
+
): Promise<void>;
|
package/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import mkdirp from "mkdirp";
|
|
3
|
+
|
|
4
|
+
const GLOBAL_STYLES = `
|
|
5
|
+
/* Hide carets */
|
|
6
|
+
* { caret-color: transparent !important; }
|
|
7
|
+
|
|
8
|
+
/* Hide scrollbars */
|
|
9
|
+
::-webkit-scrollbar {
|
|
10
|
+
display: none !important;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/* Generic hide */
|
|
14
|
+
[data-visual-test="transparent"] {
|
|
15
|
+
color: transparent !important;
|
|
16
|
+
font-family: monospace !important;
|
|
17
|
+
opacity: 0 !important;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
[data-visual-test="removed"] {
|
|
21
|
+
display: none !important;
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Check if there is `[aria-busy="true"]` element on the page.
|
|
27
|
+
*/
|
|
28
|
+
async function ensureNoBusy() {
|
|
29
|
+
const checkIsVisible = (element) =>
|
|
30
|
+
Boolean(
|
|
31
|
+
element.offsetWidth ||
|
|
32
|
+
element.offsetHeight ||
|
|
33
|
+
element.getClientRects().length
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return [...document.querySelectorAll('[aria-busy="true"]')].every(
|
|
37
|
+
(element) => !checkIsVisible(element)
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Check if the fonts are loaded
|
|
42
|
+
function waitForFontLoading() {
|
|
43
|
+
return document.fonts.status === "loaded";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function argosScreenshot(page, name, { fullPage, clip } = {}) {
|
|
47
|
+
if (!page) throw new Error("A Puppeteer `page` object is required.");
|
|
48
|
+
if (!name) throw new Error("The `name` argument is required.");
|
|
49
|
+
|
|
50
|
+
await Promise.all([
|
|
51
|
+
page.addStyleTag({ content: GLOBAL_STYLES }),
|
|
52
|
+
page.waitForFunction(ensureNoBusy),
|
|
53
|
+
page.waitForFunction(waitForFontLoading),
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
const directory = resolve(process.cwd(), "screenshots/argos");
|
|
57
|
+
await mkdirp(directory);
|
|
58
|
+
await page.screenshot({
|
|
59
|
+
path: resolve(directory, `${name}.png`),
|
|
60
|
+
type: "png",
|
|
61
|
+
fullPage,
|
|
62
|
+
clip,
|
|
63
|
+
});
|
|
64
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@argos-ci/puppeteer",
|
|
3
|
+
"description": "Visual testing solution to avoid visual regression. Puppeteer commands and utilities for Argos visual testing.",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"author": "Smooth Code",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": "github:argos-ci/argos-puppeteer",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"puppeteer",
|
|
10
|
+
"argos",
|
|
11
|
+
"automation",
|
|
12
|
+
"test automation",
|
|
13
|
+
"testing",
|
|
14
|
+
"visual testing",
|
|
15
|
+
"regression",
|
|
16
|
+
"visual regression"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=16"
|
|
23
|
+
},
|
|
24
|
+
"type": "module",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"import": "./index.js",
|
|
28
|
+
"require": "./index.cjs",
|
|
29
|
+
"types": "./index.d.ts",
|
|
30
|
+
"default": "./index.js"
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"jest": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
36
|
+
"test": "npm run jest --runInBand",
|
|
37
|
+
"format": "prettier --write .",
|
|
38
|
+
"check-format": "prettier --check .",
|
|
39
|
+
"lint": "eslint --ignore-path .gitignore .",
|
|
40
|
+
"release": "standard-version && conventional-github-releaser --preset angular"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"puppeteer": ">=1"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@argos-ci/cli": "^0.1.2",
|
|
47
|
+
"@types/jest": "^28.1.8",
|
|
48
|
+
"conventional-github-releaser": "^3.1.5",
|
|
49
|
+
"eslint": "^8.23.0",
|
|
50
|
+
"eslint-plugin-html": "^7.1.0",
|
|
51
|
+
"jest": "^29.0.1",
|
|
52
|
+
"jest-light-runner": "^0.4.0",
|
|
53
|
+
"jest-puppeteer": "^6.1.1",
|
|
54
|
+
"prettier": "^2.7.1",
|
|
55
|
+
"puppeteer": "^17.0.0",
|
|
56
|
+
"standard-version": "^9.5.0"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"mkdirp": "^1.0.4"
|
|
60
|
+
}
|
|
61
|
+
}
|