@cronn/element-snapshot 0.29.0 → 0.31.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.
@@ -161,6 +161,7 @@
161
161
  "tablist",
162
162
  "tabpanel",
163
163
  "term",
164
+ "toolbar",
164
165
  "tree"
165
166
  ]);
166
167
  //#endregion
package/dist/index.d.mts CHANGED
@@ -17,7 +17,7 @@ interface MarkdownTableSnapshotOptions {
17
17
  /**
18
18
  * Creates a Markdown table snapshot from a table or grid element
19
19
  */
20
- declare function markdownTableSnapshot(locator: Locator, options?: MarkdownTableSnapshotOptions): Promise<string>;
20
+ export declare function markdownTableSnapshot(locator: Locator, options?: MarkdownTableSnapshotOptions): Promise<string>;
21
21
  //#endregion
22
22
  //#region src/types/attributes.d.ts
23
23
  interface DisableableAttributes {
@@ -54,7 +54,7 @@ type SetValues<TSet> = TSet extends Set<infer TValue> ? TValue : never;
54
54
  type PlaywrightTarget = Page | Locator;
55
55
  //#endregion
56
56
  //#region src/types/elements/container.d.ts
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">;
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" | "toolbar" | "tree">;
58
58
  interface ContainerSnapshot extends GenericElementSnapshot<ContainerRole> {}
59
59
  type ContainerRole = SetValues<typeof CONTAINER_ROLES>;
60
60
  interface RegionSnapshot extends GenericElementSnapshot<"region"> {}
@@ -208,12 +208,12 @@ interface FilterBaseOptions {
208
208
  /**
209
209
  * Filters node snapshots based on the provided predicate function
210
210
  */
211
- declare function filter<TSnapshot extends NodeSnapshot = NodeSnapshot>(options: GuardedFilterOptions<TSnapshot>): Array<TSnapshot>;
212
- declare function filter(options: FilterOptions): Array<NodeSnapshot>;
211
+ export declare function filter<TSnapshot extends NodeSnapshot = NodeSnapshot>(options: GuardedFilterOptions<TSnapshot>): Array<TSnapshot>;
212
+ export declare function filter(options: FilterOptions): Array<NodeSnapshot>;
213
213
  /**
214
214
  * Filters node snapshots by a specific role
215
215
  */
216
- declare function filterByRole<TRole extends NodeRole>(role: TRole, snapshots: Array<NodeSnapshot>): Array<SnapshotByRole<TRole>>;
216
+ export declare function filterByRole<TRole extends NodeRole>(role: TRole, snapshots: Array<NodeSnapshot>): Array<SnapshotByRole<TRole>>;
217
217
  //#endregion
218
218
  //#region src/playwright/snapshot.d.ts
219
219
  interface SemanticSnapshotOptions {
@@ -267,7 +267,7 @@ interface SemanticSnapshotOptions {
267
267
  * @param options - Optional configuration settings for controlling the snapshot behavior
268
268
  * @return A promise that resolves to the semantic snapshot
269
269
  */
270
- declare function semanticSnapshot(target: PlaywrightTarget, options?: SemanticSnapshotOptions): Promise<unknown>;
270
+ export declare function semanticSnapshot(target: PlaywrightTarget, options?: SemanticSnapshotOptions): Promise<unknown>;
271
271
  /**
272
272
  * Captures a raw snapshot of the element matched by the provided locator.
273
273
  *
@@ -277,7 +277,7 @@ declare function semanticSnapshot(target: PlaywrightTarget, options?: SemanticSn
277
277
  * @param target - The Page or Locator instance used to identify the target element to snapshot
278
278
  * @return A promise that resolves to an array of NodeSnapshot objects representing the captured element
279
279
  */
280
- declare function rawSnapshot(target: PlaywrightTarget): Promise<Array<NodeSnapshot>>;
280
+ export declare function rawSnapshot(target: PlaywrightTarget): Promise<Array<NodeSnapshot>>;
281
281
  //#endregion
282
282
  //#region src/types/matchers.d.ts
283
283
  interface ElementSnapshotMatchers {
@@ -294,7 +294,7 @@ interface MatchMarkdownTableSnapshotFileOptions extends Omit<PlaywrightMatchText
294
294
  * @param {PlaywrightValidationFileMatcherConfig} config - Configuration options for file matching behavior
295
295
  * @return {Expect<ElementSnapshotMatchers>} An extended expect instance that includes matcher methods for element snapshot validation.
296
296
  */
297
- declare function defineElementSnapshotMatchers(config?: PlaywrightValidationFileMatcherConfig): Expect<ElementSnapshotMatchers>;
297
+ export declare function defineElementSnapshotMatchers(config?: PlaywrightValidationFileMatcherConfig): Expect<ElementSnapshotMatchers>;
298
298
  //#endregion
299
299
  //#region src/transformers/combobox-transformer.d.ts
300
300
  interface ComboboxTransformerOptions {
@@ -311,22 +311,22 @@ interface ComboboxTransformerOptions {
311
311
  *
312
312
  * Empty option lists are always omitted.
313
313
  */
314
- declare function comboboxTransformer(options?: ComboboxTransformerOptions): RoleBasedSnapshotTransformer<"combobox">;
314
+ export declare function comboboxTransformer(options?: ComboboxTransformerOptions): RoleBasedSnapshotTransformer<"combobox">;
315
315
  //#endregion
316
316
  //#region src/utils/predicates.d.ts
317
317
  /**
318
318
  * Include only elements with the specified role
319
319
  */
320
- declare function includeRole<TRole extends NodeRole>(role: TRole | Array<TRole>): GuardedFilterPredicate<SnapshotByRole<TRole>>;
320
+ export declare function includeRole<TRole extends NodeRole>(role: TRole | Array<TRole>): GuardedFilterPredicate<SnapshotByRole<TRole>>;
321
321
  /**
322
322
  * Exclude elements with the specified role
323
323
  */
324
- declare function excludeRole<TRole extends NodeRole>(role: TRole | Array<TRole>): GuardedFilterPredicate<SnapshotByRole<TRole>>;
324
+ export declare function excludeRole<TRole extends NodeRole>(role: TRole | Array<TRole>): GuardedFilterPredicate<SnapshotByRole<TRole>>;
325
325
  //#endregion
326
326
  //#region src/utils/text.d.ts
327
327
  /**
328
328
  * Aggregates and normalizes the text content of all provided snapshots
329
329
  */
330
- declare function getTextContent(snapshots: Array<NodeSnapshot>): string;
330
+ export declare function getTextContent(snapshots: Array<NodeSnapshot>): string;
331
331
  //#endregion
332
- export { type ButtonSnapshot, type CellSnapshot, type ColumnHeaderSnapshot, type ComboboxSnapshot, type ComboboxTransformerOptions, type ContainerSnapshot, type DefaultSnapshotTransformer, type DialogSnapshot, type ElementRole, type ElementSnapshot, type ElementSnapshotMatchers, type GroupSnapshot, type HeadingSnapshot, type ImageSnapshot, type InputSnapshot, type LinkSnapshot, type MarkdownTableSnapshotOptions, type MatchMarkdownTableSnapshotFileOptions, type MatchSemanticSnapshotFileOptions, type MenuItemSnapshot, type NodeRole, type NodeSnapshot, type OptionSnapshot, type ProgressbarSnapshot, type RadioGroupSnapshot, type RegionSnapshot, type RoleBasedSnapshotTransformer, type RoleBasedSnapshotTransformers, type SemanticSnapshotOptions, type SeparatorSnapshot, type SnapshotByRole, type SnapshotTransformer, type SnapshotTransformerContext, type TabSnapshot, type TextSnapshot, type TreeItemSnapshot, comboboxTransformer, defineElementSnapshotMatchers, excludeRole, filter, filterByRole, getTextContent, includeRole, markdownTableSnapshot, rawSnapshot, semanticSnapshot };
332
+ export type { ButtonSnapshot, CellSnapshot, ColumnHeaderSnapshot, ComboboxSnapshot, ComboboxTransformerOptions, ContainerSnapshot, DefaultSnapshotTransformer, DialogSnapshot, ElementRole, ElementSnapshot, ElementSnapshotMatchers, GroupSnapshot, HeadingSnapshot, ImageSnapshot, InputSnapshot, LinkSnapshot, MarkdownTableSnapshotOptions, MatchMarkdownTableSnapshotFileOptions, MatchSemanticSnapshotFileOptions, MenuItemSnapshot, NodeRole, NodeSnapshot, OptionSnapshot, ProgressbarSnapshot, RadioGroupSnapshot, RegionSnapshot, RoleBasedSnapshotTransformer, RoleBasedSnapshotTransformers, SemanticSnapshotOptions, SeparatorSnapshot, SnapshotByRole, SnapshotTransformer, SnapshotTransformerContext, TabSnapshot, TextSnapshot, TreeItemSnapshot };
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { expect } from "@playwright/test";
2
2
  import { defineJsonFileMatcher, defineTextFileMatcher } from "@cronn/playwright-file-snapshots";
3
3
  import { MarkdownTableSerializer } from "@cronn/lib-file-snapshots";
4
+ import fs from "node:fs/promises";
4
5
  import path from "node:path";
5
6
  import { packageDirectory } from "package-directory";
6
7
  //#region src/utils/guards.ts
@@ -65,7 +66,8 @@ function hasChildren(snapshot) {
65
66
  }
66
67
  //#endregion
67
68
  //#region src/playwright/proxy.ts
68
- var ElementSnapshotProxy = class {
69
+ var ElementSnapshotProxy = class ElementSnapshotProxy {
70
+ static browserLibSource = void 0;
69
71
  page;
70
72
  constructor(page) {
71
73
  this.page = page;
@@ -80,14 +82,17 @@ var ElementSnapshotProxy = class {
80
82
  return await this.page.evaluate(() => typeof window.snapshotElement === "function");
81
83
  }
82
84
  async loadLibrary() {
83
- const packageRootDir = await this.resolvePackageRootDir();
84
- const libPath = path.resolve(packageRootDir, "dist", "browser-lib.iife.js");
85
- await this.page.addScriptTag({ path: libPath });
85
+ ElementSnapshotProxy.browserLibSource ??= await this.readBrowserLibSource();
86
+ await this.page.evaluate(ElementSnapshotProxy.browserLibSource);
86
87
  }
87
- async resolvePackageRootDir() {
88
- const packageDir = await packageDirectory({ cwd: import.meta.dirname });
89
- if (packageDir === void 0) throw new Error("Unable to resolve root directory of package");
90
- return packageDir;
88
+ async readBrowserLibSource() {
89
+ const libPath = await this.resolveFromPackageRoot("dist", "browser-lib.iife.js");
90
+ return await fs.readFile(libPath, "utf8");
91
+ }
92
+ async resolveFromPackageRoot(...paths) {
93
+ const packageRoot = await packageDirectory({ cwd: import.meta.dirname });
94
+ if (packageRoot === void 0) throw new Error("Unable to resolve root directory of package");
95
+ return path.resolve(packageRoot, ...paths);
91
96
  }
92
97
  };
93
98
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cronn/element-snapshot",
3
- "version": "0.29.0",
3
+ "version": "0.31.0",
4
4
  "description": "Element snapshots for Playwright",
5
5
  "homepage": "https://cronn.github.io/file-snapshots/playwright/element-snapshots/",
6
6
  "bugs": {
@@ -25,30 +25,29 @@
25
25
  }
26
26
  },
27
27
  "dependencies": {
28
- "@cronn/lib-file-snapshots": "1.2.1",
29
- "@cronn/playwright-file-snapshots": "2.2.1",
30
- "package-directory": "8.2.0"
28
+ "@cronn/lib-file-snapshots": "1.2.2",
29
+ "@cronn/playwright-file-snapshots": "2.2.2",
30
+ "package-directory": "^8.2.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@arethetypeswrong/core": "0.18.5",
34
34
  "@cronn/shared-configs": "0.0.0",
35
35
  "@cronn/test-utils": "0.0.0",
36
- "@cronn/vitest-file-snapshots": "2.1.2",
37
- "@playwright/test": "1.62.1",
38
- "@types/node": "24.13.3",
36
+ "@cronn/vitest-file-snapshots": "3.0.0",
37
+ "@playwright/test": "1.63.0",
38
+ "@types/node": "24.13.4",
39
39
  "@typescript/native": "npm:typescript@^7.0.2",
40
- "@vitest/coverage-v8": "4.1.11",
41
- "eslint": "10.9.0",
40
+ "@vitest/coverage-v8": "5.0.0",
41
+ "eslint": "10.10.0",
42
42
  "eslint-config-prettier": "10.1.8",
43
43
  "eslint-plugin-check-file": "3.3.2",
44
44
  "eslint-plugin-unused-imports": "4.4.1",
45
45
  "publint": "0.3.24",
46
46
  "rimraf": "6.1.3",
47
- "tsdown": "0.22.14",
47
+ "tsdown": "0.23.0",
48
48
  "typescript": "npm:@typescript/typescript6@^6.0.2",
49
- "typescript-eslint": "8.67.0",
50
- "vitest": "4.1.11",
51
- "node": "runtime:24.20.0"
49
+ "typescript-eslint": "8.70.0",
50
+ "vitest": "5.0.0"
52
51
  },
53
52
  "peerDependencies": {
54
53
  "@playwright/test": "^1.55"
@@ -56,12 +55,12 @@
56
55
  "devEngines": {
57
56
  "packageManager": {
58
57
  "name": "pnpm",
59
- "version": "11.25.0",
58
+ "version": "12.6.0",
60
59
  "onFail": "download"
61
60
  },
62
61
  "runtime": {
63
62
  "name": "node",
64
- "version": "24.20.0",
63
+ "version": "24.21.0",
65
64
  "onFail": "download"
66
65
  }
67
66
  },