@cronn/element-snapshot 0.5.0 → 0.7.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.ts +17 -6
- package/dist/index.global.js +68 -14
- package/dist/types.d.ts +18 -7
- package/package.json +14 -3
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,11 @@ interface DisableableAttributes {
|
|
|
4
4
|
interface SelectableAttributes {
|
|
5
5
|
selected?: boolean;
|
|
6
6
|
}
|
|
7
|
+
interface InputStateAttributes extends DisableableAttributes {
|
|
8
|
+
readonly?: boolean;
|
|
9
|
+
required?: boolean;
|
|
10
|
+
invalid?: boolean;
|
|
11
|
+
}
|
|
7
12
|
|
|
8
13
|
interface ButtonSnapshot extends GenericElementSnapshot<"button", ButtonAttributes> {
|
|
9
14
|
}
|
|
@@ -21,12 +26,9 @@ interface InputAttributes extends CommonInputAttributes {
|
|
|
21
26
|
value?: string;
|
|
22
27
|
checked?: boolean;
|
|
23
28
|
}
|
|
24
|
-
interface CommonInputAttributes extends
|
|
29
|
+
interface CommonInputAttributes extends InputStateAttributes {
|
|
25
30
|
description?: string;
|
|
26
31
|
placeholder?: string;
|
|
27
|
-
readonly?: boolean;
|
|
28
|
-
required?: boolean;
|
|
29
|
-
invalid?: boolean;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
interface ComboboxSnapshot extends GenericElementSnapshot<"combobox", ComboboxAttributes> {
|
|
@@ -49,6 +51,9 @@ interface DialogAttributes {
|
|
|
49
51
|
modal?: boolean;
|
|
50
52
|
}
|
|
51
53
|
|
|
54
|
+
interface GroupSnapshot extends GenericElementSnapshot<"group"> {
|
|
55
|
+
}
|
|
56
|
+
|
|
52
57
|
interface HeadingSnapshot extends GenericElementSnapshot<"heading", HeadingAttributes> {
|
|
53
58
|
}
|
|
54
59
|
interface HeadingAttributes {
|
|
@@ -66,6 +71,12 @@ interface MenuitemSnapshot extends GenericElementSnapshot<"menuitem", MenuitemAt
|
|
|
66
71
|
interface MenuitemAttributes extends LinkAttributes, DisableableAttributes {
|
|
67
72
|
}
|
|
68
73
|
|
|
74
|
+
interface ProgressbarSnapshot extends GenericElementSnapshot<"progressbar", ProgressbarAttributes> {
|
|
75
|
+
}
|
|
76
|
+
interface ProgressbarAttributes {
|
|
77
|
+
value?: number;
|
|
78
|
+
}
|
|
79
|
+
|
|
69
80
|
interface TabSnapshot extends GenericElementSnapshot<"tab", TabAttributes> {
|
|
70
81
|
}
|
|
71
82
|
interface TabAttributes extends DisableableAttributes, SelectableAttributes {
|
|
@@ -86,9 +97,9 @@ interface TextSnapshot {
|
|
|
86
97
|
|
|
87
98
|
type SnapshotTargetElement = HTMLElement | SVGElement;
|
|
88
99
|
type NodeRole = ElementRole | "text";
|
|
89
|
-
type ElementRole = "heading" | "link" | "button" | "option" | "tab" | "menuitem" | "columnheader" | ContainerRole | InputRole | DialogRole;
|
|
100
|
+
type ElementRole = "heading" | "link" | "button" | "option" | "tab" | "menuitem" | "columnheader" | "group" | "progressbar" | ContainerRole | InputRole | DialogRole;
|
|
90
101
|
type NodeSnapshot = ElementSnapshot | TextSnapshot;
|
|
91
|
-
type ElementSnapshot = ContainerSnapshot | HeadingSnapshot | LinkSnapshot | ButtonSnapshot | InputSnapshot | ComboboxSnapshot | OptionSnapshot | DialogSnapshot | TabSnapshot | MenuitemSnapshot | ColumnheaderSnapshot;
|
|
102
|
+
type ElementSnapshot = ContainerSnapshot | HeadingSnapshot | LinkSnapshot | ButtonSnapshot | InputSnapshot | ComboboxSnapshot | OptionSnapshot | DialogSnapshot | TabSnapshot | MenuitemSnapshot | ColumnheaderSnapshot | GroupSnapshot | ProgressbarSnapshot;
|
|
92
103
|
interface GenericElementSnapshot<TRole extends NodeRole = NodeRole, TAttributes = unknown> {
|
|
93
104
|
role: TRole;
|
|
94
105
|
name?: string;
|
package/dist/index.global.js
CHANGED
|
@@ -72,17 +72,36 @@
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
// src/snapshots/state.ts
|
|
75
|
-
function disableableAttributes(element
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
function disableableAttributes(element) {
|
|
76
|
+
const supportsHtmlAttribute = isNativeInputElement(element) || element instanceof HTMLButtonElement;
|
|
77
|
+
const disabled = booleanAttribute(
|
|
78
|
+
supportsHtmlAttribute ? element.hasAttribute("disabled") : false
|
|
79
|
+
);
|
|
79
80
|
return {
|
|
80
|
-
disabled:
|
|
81
|
+
disabled: disabled ?? booleanAttribute(element.ariaDisabled)
|
|
81
82
|
};
|
|
82
83
|
}
|
|
83
84
|
function selectableAttributes(element) {
|
|
84
85
|
return { selected: booleanAttribute(element.ariaSelected) };
|
|
85
86
|
}
|
|
87
|
+
function inputStateAttributes(element) {
|
|
88
|
+
const supportsHtmlAttributes = isNativeInputElement(element);
|
|
89
|
+
const readonly = booleanAttribute(
|
|
90
|
+
supportsHtmlAttributes ? element.hasAttribute("readonly") : false
|
|
91
|
+
);
|
|
92
|
+
const required = booleanAttribute(
|
|
93
|
+
supportsHtmlAttributes ? element.hasAttribute("required") : false
|
|
94
|
+
);
|
|
95
|
+
return {
|
|
96
|
+
readonly: readonly ?? booleanAttribute(element.ariaReadOnly),
|
|
97
|
+
...disableableAttributes(element),
|
|
98
|
+
required: required ?? booleanAttribute(element.ariaRequired),
|
|
99
|
+
invalid: booleanAttribute(element.ariaInvalid)
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function isNativeInputElement(element) {
|
|
103
|
+
return element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement;
|
|
104
|
+
}
|
|
86
105
|
|
|
87
106
|
// src/snapshots/button.ts
|
|
88
107
|
var PRESSED_VALUES = /* @__PURE__ */ new Set(["true", "mixed", "false"]);
|
|
@@ -216,7 +235,9 @@
|
|
|
216
235
|
tfoot: "rowgroup",
|
|
217
236
|
tr: "row",
|
|
218
237
|
th: resolveTableHeaderCellRole,
|
|
219
|
-
td: "cell"
|
|
238
|
+
td: "cell",
|
|
239
|
+
fieldset: "group",
|
|
240
|
+
progress: "progressbar"
|
|
220
241
|
};
|
|
221
242
|
var CONTEXT_DEPENDENT_ROLES = {
|
|
222
243
|
banner: isTopLevelBanner,
|
|
@@ -409,10 +430,7 @@
|
|
|
409
430
|
return {
|
|
410
431
|
description: resolveDescription(element),
|
|
411
432
|
placeholder: isEmpty ? resolvePlaceholder(element) : void 0,
|
|
412
|
-
|
|
413
|
-
...disableableAttributes(element),
|
|
414
|
-
required: booleanAttribute(element.required),
|
|
415
|
-
invalid: booleanAttribute(element.ariaInvalid)
|
|
433
|
+
...inputStateAttributes(element)
|
|
416
434
|
};
|
|
417
435
|
}
|
|
418
436
|
function resolveInputValue(element) {
|
|
@@ -447,7 +465,7 @@
|
|
|
447
465
|
return void 0;
|
|
448
466
|
}
|
|
449
467
|
function resolvePlaceholder(element) {
|
|
450
|
-
if (element instanceof HTMLSelectElement) {
|
|
468
|
+
if (element instanceof HTMLSelectElement || element instanceof HTMLButtonElement) {
|
|
451
469
|
return void 0;
|
|
452
470
|
}
|
|
453
471
|
return stringAttribute(element.placeholder);
|
|
@@ -474,7 +492,7 @@
|
|
|
474
492
|
if (element instanceof HTMLSelectElement) {
|
|
475
493
|
return element.role === null || element.role === "combobox";
|
|
476
494
|
}
|
|
477
|
-
if (element instanceof HTMLInputElement) {
|
|
495
|
+
if (element instanceof HTMLInputElement || element instanceof HTMLButtonElement) {
|
|
478
496
|
return element.role === "combobox";
|
|
479
497
|
}
|
|
480
498
|
return false;
|
|
@@ -534,6 +552,22 @@
|
|
|
534
552
|
};
|
|
535
553
|
}
|
|
536
554
|
|
|
555
|
+
// src/snapshots/group.ts
|
|
556
|
+
function snapshotGroup(element) {
|
|
557
|
+
return {
|
|
558
|
+
role: "group",
|
|
559
|
+
name: resolveGroupName(element),
|
|
560
|
+
children: snapshotChildren(element)
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
function resolveGroupName(element) {
|
|
564
|
+
const legendElement = element instanceof HTMLFieldSetElement ? element.querySelector("legend") : null;
|
|
565
|
+
if (legendElement !== null) {
|
|
566
|
+
return snapshotTextContent(legendElement);
|
|
567
|
+
}
|
|
568
|
+
return resolveAccessibleName(element, false);
|
|
569
|
+
}
|
|
570
|
+
|
|
537
571
|
// src/snapshots/heading.ts
|
|
538
572
|
var LEVEL_REGEXP = /^H([1-6])$/;
|
|
539
573
|
function snapshotHeading(element) {
|
|
@@ -574,12 +608,30 @@
|
|
|
574
608
|
name: resolveAccessibleName(element),
|
|
575
609
|
attributes: {
|
|
576
610
|
...linkAttributes(element),
|
|
577
|
-
...disableableAttributes(element
|
|
611
|
+
...disableableAttributes(element)
|
|
578
612
|
},
|
|
579
613
|
children: snapshotChildren(element)
|
|
580
614
|
};
|
|
581
615
|
}
|
|
582
616
|
|
|
617
|
+
// src/snapshots/progressbar.ts
|
|
618
|
+
function snapshotProgressbar(element) {
|
|
619
|
+
return {
|
|
620
|
+
role: "progressbar",
|
|
621
|
+
name: resolveAccessibleName(element, false),
|
|
622
|
+
attributes: {
|
|
623
|
+
value: resolveValue2(element)
|
|
624
|
+
},
|
|
625
|
+
children: snapshotChildren(element)
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
function resolveValue2(element) {
|
|
629
|
+
if (element instanceof HTMLProgressElement) {
|
|
630
|
+
return element.value;
|
|
631
|
+
}
|
|
632
|
+
return numericAttribute(element.ariaValueNow);
|
|
633
|
+
}
|
|
634
|
+
|
|
583
635
|
// src/snapshots/tab.ts
|
|
584
636
|
function snapshotTab(element) {
|
|
585
637
|
return {
|
|
@@ -623,7 +675,9 @@
|
|
|
623
675
|
alertdialog: snapshotDialogWithRole("alertdialog"),
|
|
624
676
|
tab: snapshotTab,
|
|
625
677
|
menuitem: snapshotMenuitem,
|
|
626
|
-
columnheader: snapshotColumnheader
|
|
678
|
+
columnheader: snapshotColumnheader,
|
|
679
|
+
group: snapshotGroup,
|
|
680
|
+
progressbar: snapshotProgressbar
|
|
627
681
|
};
|
|
628
682
|
function snapshotElement(element) {
|
|
629
683
|
return snapshotNodeRecursive(element);
|
package/dist/types.d.ts
CHANGED
|
@@ -4,6 +4,11 @@ interface DisableableAttributes {
|
|
|
4
4
|
interface SelectableAttributes {
|
|
5
5
|
selected?: boolean;
|
|
6
6
|
}
|
|
7
|
+
interface InputStateAttributes extends DisableableAttributes {
|
|
8
|
+
readonly?: boolean;
|
|
9
|
+
required?: boolean;
|
|
10
|
+
invalid?: boolean;
|
|
11
|
+
}
|
|
7
12
|
|
|
8
13
|
interface ButtonSnapshot extends GenericElementSnapshot<"button", ButtonAttributes> {
|
|
9
14
|
}
|
|
@@ -21,12 +26,9 @@ interface InputAttributes extends CommonInputAttributes {
|
|
|
21
26
|
value?: string;
|
|
22
27
|
checked?: boolean;
|
|
23
28
|
}
|
|
24
|
-
interface CommonInputAttributes extends
|
|
29
|
+
interface CommonInputAttributes extends InputStateAttributes {
|
|
25
30
|
description?: string;
|
|
26
31
|
placeholder?: string;
|
|
27
|
-
readonly?: boolean;
|
|
28
|
-
required?: boolean;
|
|
29
|
-
invalid?: boolean;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
interface ComboboxSnapshot extends GenericElementSnapshot<"combobox", ComboboxAttributes> {
|
|
@@ -54,6 +56,9 @@ interface DialogAttributes {
|
|
|
54
56
|
modal?: boolean;
|
|
55
57
|
}
|
|
56
58
|
|
|
59
|
+
interface GroupSnapshot extends GenericElementSnapshot<"group"> {
|
|
60
|
+
}
|
|
61
|
+
|
|
57
62
|
interface HeadingSnapshot extends GenericElementSnapshot<"heading", HeadingAttributes> {
|
|
58
63
|
}
|
|
59
64
|
interface HeadingAttributes {
|
|
@@ -71,6 +76,12 @@ interface MenuitemSnapshot extends GenericElementSnapshot<"menuitem", MenuitemAt
|
|
|
71
76
|
interface MenuitemAttributes extends LinkAttributes, DisableableAttributes {
|
|
72
77
|
}
|
|
73
78
|
|
|
79
|
+
interface ProgressbarSnapshot extends GenericElementSnapshot<"progressbar", ProgressbarAttributes> {
|
|
80
|
+
}
|
|
81
|
+
interface ProgressbarAttributes {
|
|
82
|
+
value?: number;
|
|
83
|
+
}
|
|
84
|
+
|
|
74
85
|
interface TabSnapshot extends GenericElementSnapshot<"tab", TabAttributes> {
|
|
75
86
|
}
|
|
76
87
|
interface TabAttributes extends DisableableAttributes, SelectableAttributes {
|
|
@@ -90,9 +101,9 @@ interface TextSnapshot {
|
|
|
90
101
|
}
|
|
91
102
|
|
|
92
103
|
type NodeRole = ElementRole | "text";
|
|
93
|
-
type ElementRole = "heading" | "link" | "button" | "option" | "tab" | "menuitem" | "columnheader" | ContainerRole | InputRole | DialogRole;
|
|
104
|
+
type ElementRole = "heading" | "link" | "button" | "option" | "tab" | "menuitem" | "columnheader" | "group" | "progressbar" | ContainerRole | InputRole | DialogRole;
|
|
94
105
|
type NodeSnapshot = ElementSnapshot | TextSnapshot;
|
|
95
|
-
type ElementSnapshot = ContainerSnapshot | HeadingSnapshot | LinkSnapshot | ButtonSnapshot | InputSnapshot | ComboboxSnapshot | OptionSnapshot | DialogSnapshot | TabSnapshot | MenuitemSnapshot | ColumnheaderSnapshot;
|
|
106
|
+
type ElementSnapshot = ContainerSnapshot | HeadingSnapshot | LinkSnapshot | ButtonSnapshot | InputSnapshot | ComboboxSnapshot | OptionSnapshot | DialogSnapshot | TabSnapshot | MenuitemSnapshot | ColumnheaderSnapshot | GroupSnapshot | ProgressbarSnapshot;
|
|
96
107
|
interface GenericElementSnapshot<TRole extends NodeRole = NodeRole, TAttributes = unknown> {
|
|
97
108
|
role: TRole;
|
|
98
109
|
name?: string;
|
|
@@ -101,4 +112,4 @@ interface GenericElementSnapshot<TRole extends NodeRole = NodeRole, TAttributes
|
|
|
101
112
|
}
|
|
102
113
|
type SetValues<TSet> = TSet extends Set<infer TValue> ? TValue : never;
|
|
103
114
|
|
|
104
|
-
export type { ButtonSnapshot, ColumnheaderSnapshot, ComboboxSnapshot, ContainerSnapshot, DialogSnapshot, ElementRole, ElementSnapshot, HeadingSnapshot, InputSnapshot, LinkSnapshot, MenuitemSnapshot, NodeRole, NodeSnapshot, OptionSnapshot, TabSnapshot, TextSnapshot };
|
|
115
|
+
export type { ButtonSnapshot, ColumnheaderSnapshot, ComboboxSnapshot, ContainerSnapshot, DialogSnapshot, ElementRole, ElementSnapshot, GroupSnapshot, HeadingSnapshot, InputSnapshot, LinkSnapshot, MenuitemSnapshot, NodeRole, NodeSnapshot, OptionSnapshot, ProgressbarSnapshot, TabSnapshot, TextSnapshot };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cronn/element-snapshot",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Element snapshots for Playwright",
|
|
5
5
|
"author": "cronn",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -11,8 +11,19 @@
|
|
|
11
11
|
},
|
|
12
12
|
"homepage": "https://github.com/cronn/file-snapshots",
|
|
13
13
|
"engines": {
|
|
14
|
-
"node": ">=
|
|
15
|
-
|
|
14
|
+
"node": "^20 || ^22 || >=24"
|
|
15
|
+
},
|
|
16
|
+
"devEngines": {
|
|
17
|
+
"runtime": {
|
|
18
|
+
"name": "node",
|
|
19
|
+
"version": ">=24.11 <25",
|
|
20
|
+
"onFail": "error"
|
|
21
|
+
},
|
|
22
|
+
"packageManager": {
|
|
23
|
+
"name": "pnpm",
|
|
24
|
+
"version": ">=10.21 <11",
|
|
25
|
+
"onFail": "error"
|
|
26
|
+
}
|
|
16
27
|
},
|
|
17
28
|
"type": "module",
|
|
18
29
|
"exports": {
|