@cronn/element-snapshot 0.27.0 → 0.28.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.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { Expect, Locator, MatcherReturnType } from "@playwright/test";
1
+ import { Expect, Locator, MatcherReturnType, Page } from "@playwright/test";
2
2
  import { PlaywrightMatchJsonFileOptions, PlaywrightMatchTextFileOptions, PlaywrightValidationFileMatcherConfig } from "@cronn/playwright-file-snapshots";
3
3
  import { MarkdownTableNormalizer } from "@cronn/lib-file-snapshots";
4
4
  //#region src/playwright/markdown-table.d.ts
@@ -51,6 +51,7 @@ type PressedValue = true | "mixed";
51
51
  //#endregion
52
52
  //#region src/types/utils.d.ts
53
53
  type SetValues<TSet> = TSet extends Set<infer TValue> ? TValue : never;
54
+ type PlaywrightTarget = Page | Locator;
54
55
  //#endregion
55
56
  //#region src/types/elements/container.d.ts
56
57
  declare const CONTAINER_ROLES: Set<"alert" | "article" | "banner" | "blockquote" | "code" | "complementary" | "contentinfo" | "definition" | "deletion" | "descriptionlist" | "emphasis" | "form" | "grid" | "insertion" | "label" | "list" | "listbox" | "listitem" | "log" | "main" | "mark" | "menu" | "navigation" | "note" | "paragraph" | "row" | "rowgroup" | "search" | "status" | "strong" | "subscript" | "superscript" | "table" | "tablist" | "tabpanel" | "term" | "tree">;
@@ -235,25 +236,25 @@ interface SemanticSnapshotOptions {
235
236
  * This function creates a raw snapshot of the DOM element identified by the locator
236
237
  * and transforms it into a semantic representation using the provided options.
237
238
  *
238
- * @param locator - The Locator instance that identifies the DOM element to snapshot
239
+ * @param target - The Page or Locator instance that identifies the DOM element to snapshot
239
240
  * @param options - Optional configuration settings for controlling the snapshot behavior
240
241
  * @return A promise that resolves to the semantic snapshot
241
242
  */
242
- declare function semanticSnapshot(locator: Locator, options?: SemanticSnapshotOptions): Promise<unknown>;
243
+ declare function semanticSnapshot(target: PlaywrightTarget, options?: SemanticSnapshotOptions): Promise<unknown>;
243
244
  /**
244
245
  * Captures a raw snapshot of the element matched by the provided locator.
245
246
  *
246
247
  * Returns an array of node snapshots representing the current state of the matched elements
247
248
  * in the DOM, including their properties, attributes, and structure.
248
249
  *
249
- * @param locator - The Locator instance used to identify the target element to snapshot
250
+ * @param target - The Page or Locator instance used to identify the target element to snapshot
250
251
  * @return A promise that resolves to an array of NodeSnapshot objects representing the captured element
251
252
  */
252
- declare function rawSnapshot(locator: Locator): Promise<Array<NodeSnapshot>>;
253
+ declare function rawSnapshot(target: PlaywrightTarget): Promise<Array<NodeSnapshot>>;
253
254
  //#endregion
254
255
  //#region src/types/matchers.d.ts
255
256
  interface ElementSnapshotMatchers {
256
- toMatchSemanticSnapshotFile: (actual: Locator, options?: MatchSemanticSnapshotFileOptions) => Promise<MatcherReturnType>;
257
+ toMatchSemanticSnapshotFile: (actual: PlaywrightTarget, options?: MatchSemanticSnapshotFileOptions) => Promise<MatcherReturnType>;
257
258
  toMatchMarkdownTableSnapshotFile: (actual: Locator, options?: MatchMarkdownTableSnapshotFileOptions) => Promise<MatcherReturnType>;
258
259
  }
259
260
  interface MatchSemanticSnapshotFileOptions extends PlaywrightMatchJsonFileOptions, SemanticSnapshotOptions {}
package/dist/index.mjs CHANGED
@@ -199,12 +199,12 @@ var SemanticSnapshotTransformer = class {
199
199
  * This function creates a raw snapshot of the DOM element identified by the locator
200
200
  * and transforms it into a semantic representation using the provided options.
201
201
  *
202
- * @param locator - The Locator instance that identifies the DOM element to snapshot
202
+ * @param target - The Page or Locator instance that identifies the DOM element to snapshot
203
203
  * @param options - Optional configuration settings for controlling the snapshot behavior
204
204
  * @return A promise that resolves to the semantic snapshot
205
205
  */
206
- async function semanticSnapshot(locator, options) {
207
- const snapshot = await rawSnapshot(locator);
206
+ async function semanticSnapshot(target, options) {
207
+ const snapshot = await rawSnapshot(target);
208
208
  return new SemanticSnapshotTransformer(options).transform(snapshot);
209
209
  }
210
210
  /**
@@ -213,12 +213,16 @@ async function semanticSnapshot(locator, options) {
213
213
  * Returns an array of node snapshots representing the current state of the matched elements
214
214
  * in the DOM, including their properties, attributes, and structure.
215
215
  *
216
- * @param locator - The Locator instance used to identify the target element to snapshot
216
+ * @param target - The Page or Locator instance used to identify the target element to snapshot
217
217
  * @return A promise that resolves to an array of NodeSnapshot objects representing the captured element
218
218
  */
219
- async function rawSnapshot(locator) {
219
+ async function rawSnapshot(target) {
220
+ const locator = isPage(target) ? target.locator("body") : target;
220
221
  return await new ElementSnapshotProxy(locator.page()).snapshotElement(locator);
221
222
  }
223
+ function isPage(target) {
224
+ return "goto" in target && typeof target.goto === "function";
225
+ }
222
226
  //#endregion
223
227
  //#region src/playwright/markdown-table.ts
224
228
  const tableRoles = ["table", "grid"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cronn/element-snapshot",
3
- "version": "0.27.0",
3
+ "version": "0.28.0",
4
4
  "description": "Element snapshots for Playwright",
5
5
  "homepage": "https://cronn.github.io/file-snapshots/playwright/element-snapshots/",
6
6
  "bugs": {
@@ -35,17 +35,17 @@
35
35
  "@types/node": "24.13.3",
36
36
  "@typescript/native": "npm:typescript@^7.0.2",
37
37
  "@vitest/coverage-v8": "4.1.10",
38
- "eslint": "10.8.0",
38
+ "eslint": "10.8.1",
39
39
  "eslint-config-prettier": "10.1.8",
40
40
  "eslint-plugin-check-file": "3.3.2",
41
41
  "eslint-plugin-unused-imports": "4.4.1",
42
- "publint": "0.3.22",
42
+ "publint": "0.3.23",
43
43
  "rimraf": "6.1.3",
44
44
  "tsdown": "0.22.14",
45
45
  "typescript": "npm:@typescript/typescript6@^6.0.2",
46
- "typescript-eslint": "8.65.0",
46
+ "typescript-eslint": "8.67.0",
47
47
  "vitest": "4.1.10",
48
- "node": "runtime:24.18.1",
48
+ "node": "runtime:24.19.0",
49
49
  "@cronn/shared-configs": "0.0.0",
50
50
  "@cronn/test-utils": "0.0.0",
51
51
  "@cronn/vitest-file-snapshots": "2.1.2"
@@ -56,12 +56,12 @@
56
56
  "devEngines": {
57
57
  "packageManager": {
58
58
  "name": "pnpm",
59
- "version": "11.18.0",
59
+ "version": "11.22.0",
60
60
  "onFail": "download"
61
61
  },
62
62
  "runtime": {
63
63
  "name": "node",
64
- "version": "24.18.1",
64
+ "version": "24.19.0",
65
65
  "onFail": "download"
66
66
  }
67
67
  },