@argos-ci/puppeteer 3.2.0 → 4.0.0
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.d.ts +2 -2
- package/dist/index.js +41 -37
- package/package.json +12 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ScreenshotOptions, ElementHandle, Page } from 'puppeteer';
|
|
2
|
-
import { ViewportOption,
|
|
2
|
+
import { ViewportOption, StabilizationPluginOptions } from '@argos-ci/browser';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Accepts all Puppeteer screenshot options and adds Argos-specific options.
|
|
@@ -34,7 +34,7 @@ type ArgosScreenshotOptions = Omit<ScreenshotOptions, "encoding" | "type" | "omi
|
|
|
34
34
|
* Pass an object to customize the stabilization.
|
|
35
35
|
* @default true
|
|
36
36
|
*/
|
|
37
|
-
stabilize?: boolean |
|
|
37
|
+
stabilize?: boolean | StabilizationPluginOptions;
|
|
38
38
|
};
|
|
39
39
|
/**
|
|
40
40
|
* Stabilize the UI and takes a screenshot of the application under test.
|
package/dist/index.js
CHANGED
|
@@ -61,15 +61,21 @@ async function setViewportSize(page, viewportSize) {
|
|
|
61
61
|
{ width: viewportSize.width, height: viewportSize.height }
|
|
62
62
|
);
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
const {
|
|
64
|
+
function getStabilizationContext(options) {
|
|
65
|
+
const { argosCSS } = options;
|
|
66
66
|
const fullPage = checkIsFullPage(options);
|
|
67
|
+
return {
|
|
68
|
+
fullPage,
|
|
69
|
+
argosCSS,
|
|
70
|
+
options: options.stabilize
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async function beforeAll(page, options) {
|
|
74
|
+
const { disableHover = true } = options;
|
|
75
|
+
const context = getStabilizationContext(options);
|
|
67
76
|
await page.evaluate(
|
|
68
|
-
(
|
|
69
|
-
|
|
70
|
-
argosCSS: argosCSS2
|
|
71
|
-
}),
|
|
72
|
-
{ fullPage, argosCSS }
|
|
77
|
+
(context2) => window.__ARGOS__.beforeAll(context2),
|
|
78
|
+
context
|
|
73
79
|
);
|
|
74
80
|
if (disableHover) {
|
|
75
81
|
await page.mouse.move(0, 0);
|
|
@@ -81,14 +87,10 @@ async function beforeAll(page, options) {
|
|
|
81
87
|
};
|
|
82
88
|
}
|
|
83
89
|
async function beforeEach(page, options) {
|
|
84
|
-
const
|
|
85
|
-
const fullPage = checkIsFullPage(options);
|
|
90
|
+
const context = getStabilizationContext(options);
|
|
86
91
|
await page.evaluate(
|
|
87
|
-
(
|
|
88
|
-
|
|
89
|
-
argosCSS: argosCSS2
|
|
90
|
-
}),
|
|
91
|
-
{ fullPage, argosCSS }
|
|
92
|
+
(context2) => window.__ARGOS__.beforeEach(context2),
|
|
93
|
+
context
|
|
92
94
|
);
|
|
93
95
|
return async () => {
|
|
94
96
|
await page.evaluate(
|
|
@@ -96,12 +98,35 @@ async function beforeEach(page, options) {
|
|
|
96
98
|
);
|
|
97
99
|
};
|
|
98
100
|
}
|
|
101
|
+
async function waitForReadiness(page, options) {
|
|
102
|
+
const context = getStabilizationContext(options);
|
|
103
|
+
try {
|
|
104
|
+
await page.waitForFunction(
|
|
105
|
+
(context2) => window.__ARGOS__.waitFor(context2),
|
|
106
|
+
void 0,
|
|
107
|
+
context
|
|
108
|
+
);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
const reasons = await page.evaluate(
|
|
111
|
+
(context2) => window.__ARGOS__.getWaitFailureExplanations(
|
|
112
|
+
context2
|
|
113
|
+
),
|
|
114
|
+
context
|
|
115
|
+
);
|
|
116
|
+
throw new Error(
|
|
117
|
+
`
|
|
118
|
+
Failed to stabilize screenshot, found the following issues:
|
|
119
|
+
${reasons.map((reason) => `- ${reason}`).join("\n")}
|
|
120
|
+
`.trim(),
|
|
121
|
+
{ cause: error }
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
99
125
|
async function argosScreenshot(page, name, options = {}) {
|
|
100
126
|
const {
|
|
101
127
|
element,
|
|
102
128
|
viewports,
|
|
103
129
|
argosCSS: _argosCSS,
|
|
104
|
-
stabilize = true,
|
|
105
130
|
...puppeteerOptions
|
|
106
131
|
} = options;
|
|
107
132
|
if (!page) {
|
|
@@ -163,28 +188,7 @@ async function argosScreenshot(page, name, options = {}) {
|
|
|
163
188
|
return metadata;
|
|
164
189
|
}
|
|
165
190
|
async function stabilizeAndScreenshot(name2) {
|
|
166
|
-
|
|
167
|
-
const stabilizationOptions = typeof stabilize === "object" ? stabilize : {};
|
|
168
|
-
try {
|
|
169
|
-
await page.waitForFunction(
|
|
170
|
-
(options2) => window.__ARGOS__.waitFor(options2),
|
|
171
|
-
void 0,
|
|
172
|
-
stabilizationOptions
|
|
173
|
-
);
|
|
174
|
-
} catch (error) {
|
|
175
|
-
const reasons = await page.evaluate(
|
|
176
|
-
(options2) => window.__ARGOS__.getWaitFailureExplanations(options2),
|
|
177
|
-
stabilizationOptions
|
|
178
|
-
);
|
|
179
|
-
throw new Error(
|
|
180
|
-
`
|
|
181
|
-
Failed to stabilize screenshot, found the following issues:
|
|
182
|
-
${reasons.map((reason) => `- ${reason}`).join("\n")}
|
|
183
|
-
`.trim(),
|
|
184
|
-
{ cause: error }
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
191
|
+
await waitForReadiness(page, options);
|
|
188
192
|
const afterEach = await beforeEach(page, options);
|
|
189
193
|
const [screenshotPath, metadata] = await Promise.all([
|
|
190
194
|
getScreenshotPath(name2),
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@argos-ci/puppeteer",
|
|
3
3
|
"description": "Puppeteer SDK for visual testing with Argos.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "4.0.0",
|
|
5
5
|
"author": "Smooth Code",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -42,25 +42,29 @@
|
|
|
42
42
|
"puppeteer": ">=1"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@argos-ci/browser": "
|
|
46
|
-
"@argos-ci/util": "2.3.
|
|
45
|
+
"@argos-ci/browser": "4.0.0",
|
|
46
|
+
"@argos-ci/util": "2.3.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@argos-ci/cli": "2.5.
|
|
49
|
+
"@argos-ci/cli": "2.5.6",
|
|
50
50
|
"@types/jest": "^29.5.14",
|
|
51
51
|
"@types/node": "^18.19.44",
|
|
52
52
|
"expect-puppeteer": "^11.0.0",
|
|
53
53
|
"jest": "^29.0.1",
|
|
54
54
|
"jest-light-runner": "^0.6.0",
|
|
55
55
|
"jest-puppeteer": "^11.0.0",
|
|
56
|
-
"puppeteer": "^24.
|
|
56
|
+
"puppeteer": "^24.4.0"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "tsup && cp ./src/index.cjs ./dist",
|
|
60
60
|
"jest": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
61
|
-
"test": "pnpm run jest --runInBand",
|
|
61
|
+
"test-e2e": "pnpm run jest --runInBand",
|
|
62
62
|
"argos-upload": "pnpm exec argos upload screenshots --build-name \"argos-puppeteer-e2e-node-$NODE_VERSION-$OS\"",
|
|
63
|
-
"e2e": "
|
|
63
|
+
"build-e2e": "node node_modules/puppeteer/install.mjs",
|
|
64
|
+
"e2e": "pnpm run test-e2e && pnpm run argos-upload",
|
|
65
|
+
"check-types": "tsc",
|
|
66
|
+
"check-format": "prettier --check --ignore-unknown --ignore-path=../../.gitignore --ignore-path=../../.prettierignore .",
|
|
67
|
+
"lint": "eslint ."
|
|
64
68
|
},
|
|
65
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "6385df8f840714c9d77c52b2035bdbbc1b148791"
|
|
66
70
|
}
|