@cronn/element-snapshot 0.30.0 → 0.32.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/browser-lib.iife.js +8 -3
- package/dist/index.d.mts +13 -13
- package/dist/index.mjs +8 -5
- package/package.json +11 -12
package/dist/browser-lib.iife.js
CHANGED
|
@@ -161,6 +161,7 @@
|
|
|
161
161
|
"tablist",
|
|
162
162
|
"tabpanel",
|
|
163
163
|
"term",
|
|
164
|
+
"toolbar",
|
|
164
165
|
"tree"
|
|
165
166
|
]);
|
|
166
167
|
//#endregion
|
|
@@ -450,7 +451,7 @@
|
|
|
450
451
|
function resolveLabelName(element) {
|
|
451
452
|
if (element.id !== null) {
|
|
452
453
|
const referencedElement = element.ownerDocument.querySelector(attributeSelector("for", element.id));
|
|
453
|
-
if (referencedElement !== null) return resolveAccessibleTextContent(referencedElement);
|
|
454
|
+
if (referencedElement !== null) return resolveAccessibleTextContent(referencedElement, [element]);
|
|
454
455
|
}
|
|
455
456
|
const closestLabel = element.closest("label");
|
|
456
457
|
if (closestLabel !== null) return resolveAccessibleTextContent(closestLabel, [element]);
|
|
@@ -514,6 +515,11 @@
|
|
|
514
515
|
};
|
|
515
516
|
}
|
|
516
517
|
//#endregion
|
|
518
|
+
//#region src/utils/array.ts
|
|
519
|
+
function unwrapSingleItem(items) {
|
|
520
|
+
return items.length === 1 ? items.at(0) : items;
|
|
521
|
+
}
|
|
522
|
+
//#endregion
|
|
517
523
|
//#region src/browser/description.ts
|
|
518
524
|
function discribableAttributes(element) {
|
|
519
525
|
return { description: resolveDescription(element) };
|
|
@@ -599,8 +605,7 @@
|
|
|
599
605
|
if (!(element instanceof HTMLSelectElement)) return resolveAccessibleTextContent(element);
|
|
600
606
|
const selectedLabels = Array.from(element.selectedOptions).map((option) => option.label);
|
|
601
607
|
if (selectedLabels.length === 0) return;
|
|
602
|
-
|
|
603
|
-
return selectedLabels;
|
|
608
|
+
return unwrapSingleItem(selectedLabels);
|
|
604
609
|
}
|
|
605
610
|
function snapshotOptions(element) {
|
|
606
611
|
const optionsContainer = resolveOptionsContainer(element);
|
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 {
|
|
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
|
@@ -96,6 +96,11 @@ var ElementSnapshotProxy = class ElementSnapshotProxy {
|
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
98
|
//#endregion
|
|
99
|
+
//#region src/utils/array.ts
|
|
100
|
+
function unwrapSingleItem(items) {
|
|
101
|
+
return items.length === 1 ? items.at(0) : items;
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
99
104
|
//#region src/transformers/semantic-snapshot-transformer.ts
|
|
100
105
|
function semanticSnapshotTransformer(snapshot, context) {
|
|
101
106
|
if (snapshot.role === "text") return snapshot.name;
|
|
@@ -113,12 +118,12 @@ function transformElementSnapshot(snapshot, transformRecursive) {
|
|
|
113
118
|
}
|
|
114
119
|
if (hasOnlyChildren(normalizedSnapshot)) {
|
|
115
120
|
const { role, children } = normalizedSnapshot;
|
|
116
|
-
return transformedSnapshot(role,
|
|
121
|
+
return transformedSnapshot(role, unwrapSingleItem(children));
|
|
117
122
|
}
|
|
118
123
|
const { role, name, attributes, children } = normalizedSnapshot;
|
|
119
124
|
return transformedSnapshot(role, name, {
|
|
120
125
|
...attributes,
|
|
121
|
-
children: children
|
|
126
|
+
children: isEmpty(children) ? void 0 : unwrapSingleItem(children)
|
|
122
127
|
});
|
|
123
128
|
}
|
|
124
129
|
function normalizeElementSnapshot(snapshot, transformRecursive) {
|
|
@@ -195,9 +200,7 @@ var SnapshotSerializer = class {
|
|
|
195
200
|
this.defaultTransformer = options.defaultTransformer ?? semanticSnapshotTransformer;
|
|
196
201
|
}
|
|
197
202
|
transform(snapshots) {
|
|
198
|
-
|
|
199
|
-
if (transformedSnapshots.length === 1) return transformedSnapshots.at(0);
|
|
200
|
-
return transformedSnapshots;
|
|
203
|
+
return unwrapSingleItem(this.filterSnapshots(snapshots).map(this.transformSnapshotRecursive));
|
|
201
204
|
}
|
|
202
205
|
filterSnapshots(snapshots) {
|
|
203
206
|
if (this.filter === void 0) return snapshots;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cronn/element-snapshot",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"description": "Element snapshots for Playwright",
|
|
5
5
|
"homepage": "https://cronn.github.io/file-snapshots/playwright/element-snapshots/",
|
|
6
6
|
"bugs": {
|
|
@@ -33,22 +33,21 @@
|
|
|
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": "
|
|
37
|
-
"@playwright/test": "1.
|
|
38
|
-
"@types/node": "24.13.
|
|
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": "
|
|
41
|
-
"eslint": "10.
|
|
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.
|
|
47
|
+
"tsdown": "0.23.0",
|
|
48
48
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
49
|
-
"typescript-eslint": "8.
|
|
50
|
-
"vitest": "
|
|
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": "
|
|
58
|
+
"version": "12.6.0",
|
|
60
59
|
"onFail": "download"
|
|
61
60
|
},
|
|
62
61
|
"runtime": {
|
|
63
62
|
"name": "node",
|
|
64
|
-
"version": "24.
|
|
63
|
+
"version": "24.21.0",
|
|
65
64
|
"onFail": "download"
|
|
66
65
|
}
|
|
67
66
|
},
|