@argos-ci/playwright 7.3.7 → 7.4.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/README.md +2 -2
- package/dist/index.d.mts +17 -1
- package/dist/index.mjs +20 -23
- package/dist/reporter.mjs +21 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
Capture stable Argos screenshots from your [Playwright](https://playwright.dev/) tests, and report failure screenshots and traces to Argos.
|
|
19
19
|
|
|
20
|
-
Visit the [Playwright SDK documentation](https://argos-ci.com/docs/
|
|
20
|
+
Visit the [Playwright SDK documentation](https://argos-ci.com/docs/reference/playwright) for guides, the API reference, and more.
|
|
21
21
|
|
|
22
22
|
## Installation
|
|
23
23
|
|
|
@@ -65,6 +65,6 @@ test("screenshot homepage", async ({ page }) => {
|
|
|
65
65
|
|
|
66
66
|
## Links
|
|
67
67
|
|
|
68
|
-
- [Official SDK Docs](https://argos-ci.com/docs/
|
|
68
|
+
- [Official SDK Docs](https://argos-ci.com/docs/reference/playwright)
|
|
69
69
|
- [Quickstart](https://argos-ci.com/docs/quickstart/playwright-quickstart)
|
|
70
70
|
- [Discord](https://argos-ci.com/discord)
|
package/dist/index.d.mts
CHANGED
|
@@ -104,6 +104,22 @@ type ArgosScreenshotOptions = {
|
|
|
104
104
|
* @default 0.5
|
|
105
105
|
*/
|
|
106
106
|
threshold?: number;
|
|
107
|
+
/**
|
|
108
|
+
* Name, or list of names, to compare this screenshot against instead of its
|
|
109
|
+
* own name. A list is tried in order and the first name found in the baseline
|
|
110
|
+
* build wins, which lets a brand new screenshot fall back to an existing one
|
|
111
|
+
* rather than showing up as added.
|
|
112
|
+
*
|
|
113
|
+
* The screenshot's own name is not implicitly included: list it first to keep
|
|
114
|
+
* comparing against itself when it exists.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* // Compare "home-variant-b" against itself, or against "home" if it is new.
|
|
118
|
+
* argosScreenshot(page, "home-variant-b", {
|
|
119
|
+
* baseName: ["home-variant-b", "home"],
|
|
120
|
+
* })
|
|
121
|
+
*/
|
|
122
|
+
baseName?: string | string[];
|
|
107
123
|
/**
|
|
108
124
|
* Folder where the screenshots will be saved if not using the Argos reporter.
|
|
109
125
|
* @default "./screenshots"
|
|
@@ -143,7 +159,7 @@ type ArgosScreenshotOptions = {
|
|
|
143
159
|
*
|
|
144
160
|
* @example
|
|
145
161
|
* argosScreenshot(page, "my-screenshot")
|
|
146
|
-
* @see https://argos-ci.com/docs/
|
|
162
|
+
* @see https://argos-ci.com/docs/reference/playwright
|
|
147
163
|
*/
|
|
148
164
|
declare function argosScreenshot(
|
|
149
165
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
-
import { getGitRepositoryPath, getMetadataPath, getScreenshotName, readVersionFromPackage, validateThreshold, writeMetadata } from "@argos-ci/util";
|
|
3
|
+
import { getGitRepositoryPath, getMetadataPath, getScreenshotName, normalizeBaseNames, readVersionFromPackage, validateThreshold, writeMetadata } from "@argos-ci/util";
|
|
4
4
|
import { dirname, relative, resolve } from "node:path";
|
|
5
5
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
6
6
|
import { getGlobalScript, resolveViewport } from "@argos-ci/browser";
|
|
@@ -196,21 +196,17 @@ async function setViewportSize(page, viewportSize) {
|
|
|
196
196
|
/**
|
|
197
197
|
* Get the snapshot names based on the test info.
|
|
198
198
|
*/
|
|
199
|
-
function getSnapshotNames(name, testInfo) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
name: projectName,
|
|
208
|
-
baseName: null
|
|
209
|
-
};
|
|
210
|
-
}
|
|
199
|
+
function getSnapshotNames(name, testInfo, baseNames) {
|
|
200
|
+
const prefix = testInfo?.project.name ? `${testInfo.project.name}/` : "";
|
|
201
|
+
const prefixedName = `${prefix}${name}`;
|
|
202
|
+
const prefixedBaseNames = baseNames && baseNames.length > 0 ? baseNames.map((baseName) => `${prefix}${baseName}`) : null;
|
|
203
|
+
if (testInfo && testInfo.repeatEachIndex > 0) return {
|
|
204
|
+
name: `${prefixedName} repeat-${testInfo.repeatEachIndex}`,
|
|
205
|
+
baseNames: prefixedBaseNames ?? [prefixedName]
|
|
206
|
+
};
|
|
211
207
|
return {
|
|
212
|
-
name,
|
|
213
|
-
|
|
208
|
+
name: prefixedName,
|
|
209
|
+
baseNames: prefixedBaseNames
|
|
214
210
|
};
|
|
215
211
|
}
|
|
216
212
|
/**
|
|
@@ -261,7 +257,7 @@ async function getPathAndMetadata(args) {
|
|
|
261
257
|
const viewport = viewportSize ?? getMetadataOverrides()?.viewport;
|
|
262
258
|
if (viewport) metadata.viewport = viewport;
|
|
263
259
|
metadata.transient = {};
|
|
264
|
-
if (names.
|
|
260
|
+
if (names.baseNames) metadata.transient.baseName = names.baseNames.map((baseName) => `${baseName}${extension}`);
|
|
265
261
|
return {
|
|
266
262
|
metadata,
|
|
267
263
|
path
|
|
@@ -425,10 +421,11 @@ const DEFAULT_SCREENSHOT_ROOT = "./screenshots";
|
|
|
425
421
|
*
|
|
426
422
|
* @example
|
|
427
423
|
* argosScreenshot(page, "my-screenshot")
|
|
428
|
-
* @see https://argos-ci.com/docs/
|
|
424
|
+
* @see https://argos-ci.com/docs/reference/playwright
|
|
429
425
|
*/
|
|
430
426
|
async function argosScreenshot(handler, name, options = {}) {
|
|
431
|
-
const { element, has, hasText, hasNot, hasNotText, viewports, argosCSS: _argosCSS, root = DEFAULT_SCREENSHOT_ROOT, ariaSnapshot, disableHover = true, ...playwrightOptions } = options;
|
|
427
|
+
const { element, has, hasText, hasNot, hasNotText, viewports, argosCSS: _argosCSS, root = DEFAULT_SCREENSHOT_ROOT, ariaSnapshot, disableHover = true, baseName, ...playwrightOptions } = options;
|
|
428
|
+
const baseNames = normalizeBaseNames(baseName);
|
|
432
429
|
if (!handler) throw new Error("A Playwright `handler` object is required.");
|
|
433
430
|
if (!name) throw new Error("The `name` argument is required.");
|
|
434
431
|
const screenshotTarget = typeof element === "string" ? handler.locator(element, {
|
|
@@ -448,8 +445,8 @@ async function argosScreenshot(handler, name, options = {}) {
|
|
|
448
445
|
const fullPage = options.fullPage !== void 0 ? options.fullPage : screenshotTarget === handler;
|
|
449
446
|
const context = getStabilizationContext(options);
|
|
450
447
|
const afterAll = await beforeAll(handler, context, { disableHover });
|
|
451
|
-
const stabilizeAndScreenshot = async (name) => {
|
|
452
|
-
const names = getSnapshotNames(name, testInfo);
|
|
448
|
+
const stabilizeAndScreenshot = async (name, baseNames) => {
|
|
449
|
+
const names = getSnapshotNames(name, testInfo, baseNames);
|
|
453
450
|
const { path: screenshotPath, metadata } = await getPathAndMetadata({
|
|
454
451
|
handler,
|
|
455
452
|
extension: PNG_EXTENSION,
|
|
@@ -480,7 +477,7 @@ async function argosScreenshot(handler, name, options = {}) {
|
|
|
480
477
|
...metadata,
|
|
481
478
|
transient: {
|
|
482
479
|
parentName: `${names.name}${PNG_EXTENSION}`,
|
|
483
|
-
...
|
|
480
|
+
...names.baseNames ? { baseName: names.baseNames.map((baseName) => screenshotToSnapshotPath(`${baseName}${PNG_EXTENSION}`)) } : {}
|
|
484
481
|
}
|
|
485
482
|
};
|
|
486
483
|
await Promise.all([snapshotTarget.ariaSnapshot().then((snapshot) => {
|
|
@@ -531,13 +528,13 @@ async function argosScreenshot(handler, name, options = {}) {
|
|
|
531
528
|
for (const viewport of viewports) {
|
|
532
529
|
const viewportSize = resolveViewport(viewport);
|
|
533
530
|
await setViewportSize(handler, viewportSize);
|
|
534
|
-
const attachments = await stabilizeAndScreenshot(getScreenshotName(name, { viewportWidth: viewportSize.width }));
|
|
531
|
+
const attachments = await stabilizeAndScreenshot(getScreenshotName(name, { viewportWidth: viewportSize.width }), baseNames?.map((baseName) => getScreenshotName(baseName, { viewportWidth: viewportSize.width })) ?? null);
|
|
535
532
|
allAttachments.push(...attachments);
|
|
536
533
|
}
|
|
537
534
|
if (!originalViewportSize) throw new Error(`Invariant: viewport size must be saved`);
|
|
538
535
|
await setViewportSize(handler, originalViewportSize);
|
|
539
536
|
} else {
|
|
540
|
-
const attachments = await stabilizeAndScreenshot(name);
|
|
537
|
+
const attachments = await stabilizeAndScreenshot(name, baseNames);
|
|
541
538
|
allAttachments.push(...attachments);
|
|
542
539
|
}
|
|
543
540
|
await afterAll();
|
package/dist/reporter.mjs
CHANGED
|
@@ -169,6 +169,26 @@ const debug = createDebug("@argos-ci/playwright");
|
|
|
169
169
|
function checkIsDynamicBuildName(buildName) {
|
|
170
170
|
return Boolean(typeof buildName === "object" && buildName);
|
|
171
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Chromium launch arguments recommended to stabilize font rendering
|
|
174
|
+
* and get consistent Argos screenshots.
|
|
175
|
+
*/
|
|
176
|
+
const RECOMMENDED_CHROMIUM_ARGS = ["--disable-lcd-text", "--font-render-hinting=none"];
|
|
177
|
+
/**
|
|
178
|
+
* Warn if the Playwright config is missing the recommended Chromium launch
|
|
179
|
+
* options used to stabilize screenshots.
|
|
180
|
+
*/
|
|
181
|
+
function checkLaunchOptions(config) {
|
|
182
|
+
for (const project of config.projects) {
|
|
183
|
+
if ((project.use.browserName ?? "chromium") !== "chromium") continue;
|
|
184
|
+
const args = project.use.launchOptions?.args ?? [];
|
|
185
|
+
const missing = RECOMMENDED_CHROMIUM_ARGS.filter((arg) => !args.includes(arg));
|
|
186
|
+
if (missing.length > 0) {
|
|
187
|
+
const projectLabel = project.name || "default";
|
|
188
|
+
console.warn(chalk.yellow(`⚠️ Argos: Playwright project "${projectLabel}" is missing recommended launchOptions args: ${missing.join(", ")}.\n Add them to stabilize font rendering and get consistent screenshots. See https://argos-ci.com/docs/reference/playwright`));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
172
192
|
function createArgosReporterOptions(options) {
|
|
173
193
|
return options;
|
|
174
194
|
}
|
|
@@ -230,6 +250,7 @@ var ArgosReporter = class {
|
|
|
230
250
|
onBegin(config) {
|
|
231
251
|
debug("ArgosReporter:onBegin");
|
|
232
252
|
this.playwrightConfig = config;
|
|
253
|
+
checkLaunchOptions(config);
|
|
233
254
|
}
|
|
234
255
|
async onTestEnd(test, result) {
|
|
235
256
|
const buildName = checkIsDynamicBuildName(this.config.buildName) ? this.config.buildName.get(test) : this.config.buildName;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@argos-ci/playwright",
|
|
3
3
|
"description": "Playwright SDK for visual testing with Argos.",
|
|
4
|
-
"version": "7.
|
|
4
|
+
"version": "7.4.0",
|
|
5
5
|
"author": "Smooth Code",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"url": "https://github.com/argos-ci/argos-javascript.git",
|
|
10
10
|
"directory": "packages/playwright"
|
|
11
11
|
},
|
|
12
|
-
"homepage": "https://argos-ci.com/docs/
|
|
12
|
+
"homepage": "https://argos-ci.com/docs/reference/playwright",
|
|
13
13
|
"bugs": {
|
|
14
14
|
"url": "https://github.com/argos-ci/argos-javascript/issues"
|
|
15
15
|
},
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@argos-ci/browser": "6.4.4",
|
|
51
|
-
"@argos-ci/core": "6.
|
|
52
|
-
"@argos-ci/util": "4.0
|
|
51
|
+
"@argos-ci/core": "6.7.0",
|
|
52
|
+
"@argos-ci/util": "4.1.0",
|
|
53
53
|
"chalk": "^5.6.2",
|
|
54
54
|
"debug": "^4.4.3"
|
|
55
55
|
},
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"lint": "eslint .",
|
|
70
70
|
"test": "vitest src"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "a3083087b11004e0b315e2d14f1e9179cbd56da2"
|
|
73
73
|
}
|