@argos-ci/puppeteer 3.1.3 → 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 +55 -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,32 +61,72 @@ 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
|
-
|
|
77
|
+
(context2) => window.__ARGOS__.beforeAll(context2),
|
|
78
|
+
context
|
|
70
79
|
);
|
|
71
80
|
if (disableHover) {
|
|
72
81
|
await page.mouse.move(0, 0);
|
|
73
82
|
}
|
|
74
83
|
return async () => {
|
|
75
84
|
await page.evaluate(
|
|
76
|
-
(
|
|
77
|
-
fullPage: fullPage2,
|
|
78
|
-
argosCSS: argosCSS2
|
|
79
|
-
}),
|
|
80
|
-
{ fullPage, argosCSS }
|
|
85
|
+
() => window.__ARGOS__.afterAll()
|
|
81
86
|
);
|
|
82
87
|
};
|
|
83
88
|
}
|
|
89
|
+
async function beforeEach(page, options) {
|
|
90
|
+
const context = getStabilizationContext(options);
|
|
91
|
+
await page.evaluate(
|
|
92
|
+
(context2) => window.__ARGOS__.beforeEach(context2),
|
|
93
|
+
context
|
|
94
|
+
);
|
|
95
|
+
return async () => {
|
|
96
|
+
await page.evaluate(
|
|
97
|
+
() => window.__ARGOS__.afterEach()
|
|
98
|
+
);
|
|
99
|
+
};
|
|
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
|
+
}
|
|
84
125
|
async function argosScreenshot(page, name, options = {}) {
|
|
85
126
|
const {
|
|
86
127
|
element,
|
|
87
128
|
viewports,
|
|
88
129
|
argosCSS: _argosCSS,
|
|
89
|
-
stabilize = true,
|
|
90
130
|
...puppeteerOptions
|
|
91
131
|
} = options;
|
|
92
132
|
if (!page) {
|
|
@@ -100,7 +140,7 @@ async function argosScreenshot(page, name, options = {}) {
|
|
|
100
140
|
// Inject Argos script into the page
|
|
101
141
|
injectArgos(page)
|
|
102
142
|
]);
|
|
103
|
-
const
|
|
143
|
+
const afterAll = await beforeAll(page, options);
|
|
104
144
|
const fullPage = checkIsFullPage(options);
|
|
105
145
|
async function collectMetadata() {
|
|
106
146
|
const [
|
|
@@ -148,28 +188,8 @@ async function argosScreenshot(page, name, options = {}) {
|
|
|
148
188
|
return metadata;
|
|
149
189
|
}
|
|
150
190
|
async function stabilizeAndScreenshot(name2) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
try {
|
|
154
|
-
await page.waitForFunction(
|
|
155
|
-
(options2) => window.__ARGOS__.checkIsStable(options2),
|
|
156
|
-
void 0,
|
|
157
|
-
stabilizationOptions
|
|
158
|
-
);
|
|
159
|
-
} catch (error) {
|
|
160
|
-
const reasons = await page.evaluate(
|
|
161
|
-
(options2) => window.__ARGOS__.getStabilityFailureReasons(options2),
|
|
162
|
-
stabilizationOptions
|
|
163
|
-
);
|
|
164
|
-
throw new Error(
|
|
165
|
-
`
|
|
166
|
-
Failed to stabilize screenshot, found the following issues:
|
|
167
|
-
${reasons.map((reason) => `- ${reason}`).join("\n")}
|
|
168
|
-
`.trim(),
|
|
169
|
-
{ cause: error }
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
191
|
+
await waitForReadiness(page, options);
|
|
192
|
+
const afterEach = await beforeEach(page, options);
|
|
173
193
|
const [screenshotPath, metadata] = await Promise.all([
|
|
174
194
|
getScreenshotPath(name2),
|
|
175
195
|
collectMetadata()
|
|
@@ -193,9 +213,7 @@ ${reasons.map((reason) => `- ${reason}`).join("\n")}
|
|
|
193
213
|
} else {
|
|
194
214
|
await element.screenshot(screenshotOptions);
|
|
195
215
|
}
|
|
196
|
-
await
|
|
197
|
-
() => window.__ARGOS__.afterEach()
|
|
198
|
-
);
|
|
216
|
+
await afterEach();
|
|
199
217
|
}
|
|
200
218
|
if (viewports) {
|
|
201
219
|
for (const viewport of viewports) {
|
|
@@ -209,7 +227,7 @@ ${reasons.map((reason) => `- ${reason}`).join("\n")}
|
|
|
209
227
|
} else {
|
|
210
228
|
await stabilizeAndScreenshot(name);
|
|
211
229
|
}
|
|
212
|
-
await
|
|
230
|
+
await afterAll();
|
|
213
231
|
}
|
|
214
232
|
export {
|
|
215
233
|
argosScreenshot
|
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
|
}
|