@argos-ci/puppeteer 6.0.22 → 6.1.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 CHANGED
@@ -17,11 +17,11 @@
17
17
 
18
18
  Capture stable Argos screenshots from your [Puppeteer](https://github.com/puppeteer/puppeteer) tests.
19
19
 
20
- Visit the [Puppeteer SDK documentation](https://argos-ci.com/docs/sdks-reference/puppeteer) for guides, the API reference, and more.
20
+ Visit the [Puppeteer SDK documentation](https://argos-ci.com/docs/reference/puppeteer) for guides, the API reference, and more.
21
21
 
22
22
  ## Installation
23
23
 
24
- Install the SDK alongside the [Argos CLI](https://argos-ci.com/docs/sdks-reference/argos-command-line-interface-cli), which uploads the screenshots to Argos:
24
+ Install the SDK alongside the [Argos CLI](https://argos-ci.com/docs/reference/argos-command-line-interface-cli), which uploads the screenshots to Argos:
25
25
 
26
26
  ```sh
27
27
  npm install --save-dev @argos-ci/puppeteer @argos-ci/cli
@@ -50,6 +50,6 @@ npx @argos-ci/cli upload ./screenshots
50
50
 
51
51
  ## Links
52
52
 
53
- - [Official SDK Docs](https://argos-ci.com/docs/sdks-reference/puppeteer)
53
+ - [Official SDK Docs](https://argos-ci.com/docs/reference/puppeteer)
54
54
  - [Quickstart](https://argos-ci.com/docs/quickstart/puppeteer-quickstart)
55
55
  - [Discord](https://argos-ci.com/discord)
package/dist/index.d.mts CHANGED
@@ -29,6 +29,22 @@ type ArgosScreenshotOptions = Omit<ScreenshotOptions, "encoding" | "type" | "omi
29
29
  * @default 0.5
30
30
  */
31
31
  threshold?: number;
32
+ /**
33
+ * Name, or list of names, to compare this screenshot against instead of its
34
+ * own name. A list is tried in order and the first name found in the baseline
35
+ * build wins, which lets a brand new screenshot fall back to an existing one
36
+ * rather than showing up as added.
37
+ *
38
+ * The screenshot's own name is not implicitly included: list it first to keep
39
+ * comparing against itself when it exists.
40
+ *
41
+ * @example
42
+ * // Compare "home-variant-b" against itself, or against "home" if it is new.
43
+ * argosScreenshot(page, "home-variant-b", {
44
+ * baseName: ["home-variant-b", "home"],
45
+ * })
46
+ */
47
+ baseName?: string | string[];
32
48
  /**
33
49
  * Wait for the UI to stabilize before taking the screenshot.
34
50
  * Set to `false` to disable stabilization.
@@ -46,7 +62,7 @@ type ArgosScreenshotOptions = Omit<ScreenshotOptions, "encoding" | "type" | "omi
46
62
  *
47
63
  * @example
48
64
  * argosScreenshot(page, "my-screenshot")
49
- * @see https://argos-ci.com/docs/sdks-reference/puppeteer
65
+ * @see https://argos-ci.com/docs/reference/puppeteer
50
66
  */
51
67
  declare function argosScreenshot(
52
68
  /**
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ import { createRequire } from "node:module";
2
2
  import { resolve } from "node:path";
3
3
  import { mkdir } from "node:fs/promises";
4
4
  import { getGlobalScript, resolveViewport } from "@argos-ci/browser";
5
- import { getScreenshotName, readVersionFromPackage, validateThreshold, writeMetadata } from "@argos-ci/util";
5
+ import { getScreenshotName, normalizeBaseNames, readVersionFromPackage, validateThreshold, writeMetadata } from "@argos-ci/util";
6
6
  //#region src/index.ts
7
7
  const require = createRequire(import.meta.url);
8
8
  /**
@@ -104,16 +104,17 @@ ${reasons.map((reason) => `- ${reason}`).join("\n")}
104
104
  *
105
105
  * @example
106
106
  * argosScreenshot(page, "my-screenshot")
107
- * @see https://argos-ci.com/docs/sdks-reference/puppeteer
107
+ * @see https://argos-ci.com/docs/reference/puppeteer
108
108
  */
109
109
  async function argosScreenshot(page, name, options = {}) {
110
- const { element, viewports, argosCSS: _argosCSS, ...puppeteerOptions } = options;
110
+ const { element, viewports, argosCSS: _argosCSS, baseName, ...puppeteerOptions } = options;
111
+ const baseNames = normalizeBaseNames(baseName);
111
112
  if (!page) throw new Error("A Puppeteer `page` object is required.");
112
113
  if (!name) throw new Error("The `name` argument is required.");
113
114
  const [originalViewport] = await Promise.all([getViewport(page), injectArgos(page)]);
114
115
  const afterAll = await beforeAll(page, options);
115
116
  const fullPage = checkIsFullPage(options);
116
- async function collectMetadata() {
117
+ async function collectMetadata(baseNames) {
117
118
  const [colorScheme, mediaType, puppeteerVersion, argosPuppeteerVersion, { browserName, browserVersion }] = await Promise.all([
118
119
  page.evaluate(() => window.__ARGOS__.getColorScheme()),
119
120
  page.evaluate(() => window.__ARGOS__.getMediaType()),
@@ -145,6 +146,7 @@ async function argosScreenshot(page, name, options = {}) {
145
146
  }
146
147
  };
147
148
  metadata.transient = {};
149
+ if (baseNames) metadata.transient.baseName = baseNames;
148
150
  if (options?.tag) metadata.tags = Array.isArray(options.tag) ? options.tag : [options.tag];
149
151
  if (options?.threshold !== void 0) {
150
152
  validateThreshold(options.threshold);
@@ -152,11 +154,11 @@ async function argosScreenshot(page, name, options = {}) {
152
154
  }
153
155
  return metadata;
154
156
  }
155
- async function stabilizeAndScreenshot(name) {
157
+ async function stabilizeAndScreenshot(name, baseNames) {
156
158
  await waitForReadiness(page, options);
157
159
  const afterEach = await beforeEach(page, options);
158
160
  await waitForReadiness(page, options);
159
- const [screenshotPath, metadata] = await Promise.all([getScreenshotPath(name), collectMetadata()]);
161
+ const [screenshotPath, metadata] = await Promise.all([getScreenshotPath(name), collectMetadata(baseNames)]);
160
162
  await writeMetadata(screenshotPath, metadata);
161
163
  const screenshotOptions = {
162
164
  path: screenshotPath,
@@ -177,10 +179,10 @@ async function argosScreenshot(page, name, options = {}) {
177
179
  for (const viewport of viewports) {
178
180
  const viewportSize = resolveViewport(viewport);
179
181
  await setViewportSize(page, viewportSize);
180
- await stabilizeAndScreenshot(getScreenshotName(name, { viewportWidth: viewportSize.width }));
182
+ await stabilizeAndScreenshot(getScreenshotName(name, { viewportWidth: viewportSize.width }), baseNames?.map((baseName) => getScreenshotName(baseName, { viewportWidth: viewportSize.width })) ?? null);
181
183
  }
182
184
  await setViewportSize(page, originalViewport);
183
- } else await stabilizeAndScreenshot(name);
185
+ } else await stabilizeAndScreenshot(name, baseNames);
184
186
  await afterAll();
185
187
  }
186
188
  //#endregion
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": "6.0.22",
4
+ "version": "6.1.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/puppeteer"
11
11
  },
12
- "homepage": "https://argos-ci.com/docs/sdks-reference/puppeteer",
12
+ "homepage": "https://argos-ci.com/docs/reference/puppeteer",
13
13
  "bugs": {
14
14
  "url": "https://github.com/argos-ci/argos-javascript/issues"
15
15
  },
@@ -43,10 +43,10 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@argos-ci/browser": "6.4.4",
46
- "@argos-ci/util": "4.0.4"
46
+ "@argos-ci/util": "4.1.0"
47
47
  },
48
48
  "devDependencies": {
49
- "@argos-ci/cli": "6.4.0",
49
+ "@argos-ci/cli": "6.5.0",
50
50
  "@types/jest": "^30.0.0",
51
51
  "@types/node": "catalog:",
52
52
  "expect-puppeteer": "^11.0.0",
@@ -66,5 +66,5 @@
66
66
  "check-format": "prettier --check --ignore-unknown --ignore-path=../../.gitignore --ignore-path=../../.prettierignore .",
67
67
  "lint": "eslint ."
68
68
  },
69
- "gitHead": "2fda63bc0d4ac0f1a2ef6a181361e8b0c4de8349"
69
+ "gitHead": "a3083087b11004e0b315e2d14f1e9179cbd56da2"
70
70
  }