@cronn/element-snapshot 0.5.0 → 0.6.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 +11 -6
- package/dist/index.global.js +48 -14
- package/dist/types.d.ts +12 -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 {
|
|
@@ -86,9 +91,9 @@ interface TextSnapshot {
|
|
|
86
91
|
|
|
87
92
|
type SnapshotTargetElement = HTMLElement | SVGElement;
|
|
88
93
|
type NodeRole = ElementRole | "text";
|
|
89
|
-
type ElementRole = "heading" | "link" | "button" | "option" | "tab" | "menuitem" | "columnheader" | ContainerRole | InputRole | DialogRole;
|
|
94
|
+
type ElementRole = "heading" | "link" | "button" | "option" | "tab" | "menuitem" | "columnheader" | "group" | ContainerRole | InputRole | DialogRole;
|
|
90
95
|
type NodeSnapshot = ElementSnapshot | TextSnapshot;
|
|
91
|
-
type ElementSnapshot = ContainerSnapshot | HeadingSnapshot | LinkSnapshot | ButtonSnapshot | InputSnapshot | ComboboxSnapshot | OptionSnapshot | DialogSnapshot | TabSnapshot | MenuitemSnapshot | ColumnheaderSnapshot;
|
|
96
|
+
type ElementSnapshot = ContainerSnapshot | HeadingSnapshot | LinkSnapshot | ButtonSnapshot | InputSnapshot | ComboboxSnapshot | OptionSnapshot | DialogSnapshot | TabSnapshot | MenuitemSnapshot | ColumnheaderSnapshot | GroupSnapshot;
|
|
92
97
|
interface GenericElementSnapshot<TRole extends NodeRole = NodeRole, TAttributes = unknown> {
|
|
93
98
|
role: TRole;
|
|
94
99
|
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,8 @@
|
|
|
216
235
|
tfoot: "rowgroup",
|
|
217
236
|
tr: "row",
|
|
218
237
|
th: resolveTableHeaderCellRole,
|
|
219
|
-
td: "cell"
|
|
238
|
+
td: "cell",
|
|
239
|
+
fieldset: "group"
|
|
220
240
|
};
|
|
221
241
|
var CONTEXT_DEPENDENT_ROLES = {
|
|
222
242
|
banner: isTopLevelBanner,
|
|
@@ -409,10 +429,7 @@
|
|
|
409
429
|
return {
|
|
410
430
|
description: resolveDescription(element),
|
|
411
431
|
placeholder: isEmpty ? resolvePlaceholder(element) : void 0,
|
|
412
|
-
|
|
413
|
-
...disableableAttributes(element),
|
|
414
|
-
required: booleanAttribute(element.required),
|
|
415
|
-
invalid: booleanAttribute(element.ariaInvalid)
|
|
432
|
+
...inputStateAttributes(element)
|
|
416
433
|
};
|
|
417
434
|
}
|
|
418
435
|
function resolveInputValue(element) {
|
|
@@ -447,7 +464,7 @@
|
|
|
447
464
|
return void 0;
|
|
448
465
|
}
|
|
449
466
|
function resolvePlaceholder(element) {
|
|
450
|
-
if (element instanceof HTMLSelectElement) {
|
|
467
|
+
if (element instanceof HTMLSelectElement || element instanceof HTMLButtonElement) {
|
|
451
468
|
return void 0;
|
|
452
469
|
}
|
|
453
470
|
return stringAttribute(element.placeholder);
|
|
@@ -474,7 +491,7 @@
|
|
|
474
491
|
if (element instanceof HTMLSelectElement) {
|
|
475
492
|
return element.role === null || element.role === "combobox";
|
|
476
493
|
}
|
|
477
|
-
if (element instanceof HTMLInputElement) {
|
|
494
|
+
if (element instanceof HTMLInputElement || element instanceof HTMLButtonElement) {
|
|
478
495
|
return element.role === "combobox";
|
|
479
496
|
}
|
|
480
497
|
return false;
|
|
@@ -534,6 +551,22 @@
|
|
|
534
551
|
};
|
|
535
552
|
}
|
|
536
553
|
|
|
554
|
+
// src/snapshots/group.ts
|
|
555
|
+
function snapshotGroup(element) {
|
|
556
|
+
return {
|
|
557
|
+
role: "group",
|
|
558
|
+
name: resolveGroupName(element),
|
|
559
|
+
children: snapshotChildren(element)
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
function resolveGroupName(element) {
|
|
563
|
+
const legendElement = element instanceof HTMLFieldSetElement ? element.querySelector("legend") : null;
|
|
564
|
+
if (legendElement !== null) {
|
|
565
|
+
return snapshotTextContent(legendElement);
|
|
566
|
+
}
|
|
567
|
+
return resolveAccessibleName(element, false);
|
|
568
|
+
}
|
|
569
|
+
|
|
537
570
|
// src/snapshots/heading.ts
|
|
538
571
|
var LEVEL_REGEXP = /^H([1-6])$/;
|
|
539
572
|
function snapshotHeading(element) {
|
|
@@ -574,7 +607,7 @@
|
|
|
574
607
|
name: resolveAccessibleName(element),
|
|
575
608
|
attributes: {
|
|
576
609
|
...linkAttributes(element),
|
|
577
|
-
...disableableAttributes(element
|
|
610
|
+
...disableableAttributes(element)
|
|
578
611
|
},
|
|
579
612
|
children: snapshotChildren(element)
|
|
580
613
|
};
|
|
@@ -623,7 +656,8 @@
|
|
|
623
656
|
alertdialog: snapshotDialogWithRole("alertdialog"),
|
|
624
657
|
tab: snapshotTab,
|
|
625
658
|
menuitem: snapshotMenuitem,
|
|
626
|
-
columnheader: snapshotColumnheader
|
|
659
|
+
columnheader: snapshotColumnheader,
|
|
660
|
+
group: snapshotGroup
|
|
627
661
|
};
|
|
628
662
|
function snapshotElement(element) {
|
|
629
663
|
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 {
|
|
@@ -90,9 +95,9 @@ interface TextSnapshot {
|
|
|
90
95
|
}
|
|
91
96
|
|
|
92
97
|
type NodeRole = ElementRole | "text";
|
|
93
|
-
type ElementRole = "heading" | "link" | "button" | "option" | "tab" | "menuitem" | "columnheader" | ContainerRole | InputRole | DialogRole;
|
|
98
|
+
type ElementRole = "heading" | "link" | "button" | "option" | "tab" | "menuitem" | "columnheader" | "group" | ContainerRole | InputRole | DialogRole;
|
|
94
99
|
type NodeSnapshot = ElementSnapshot | TextSnapshot;
|
|
95
|
-
type ElementSnapshot = ContainerSnapshot | HeadingSnapshot | LinkSnapshot | ButtonSnapshot | InputSnapshot | ComboboxSnapshot | OptionSnapshot | DialogSnapshot | TabSnapshot | MenuitemSnapshot | ColumnheaderSnapshot;
|
|
100
|
+
type ElementSnapshot = ContainerSnapshot | HeadingSnapshot | LinkSnapshot | ButtonSnapshot | InputSnapshot | ComboboxSnapshot | OptionSnapshot | DialogSnapshot | TabSnapshot | MenuitemSnapshot | ColumnheaderSnapshot | GroupSnapshot;
|
|
96
101
|
interface GenericElementSnapshot<TRole extends NodeRole = NodeRole, TAttributes = unknown> {
|
|
97
102
|
role: TRole;
|
|
98
103
|
name?: string;
|
|
@@ -101,4 +106,4 @@ interface GenericElementSnapshot<TRole extends NodeRole = NodeRole, TAttributes
|
|
|
101
106
|
}
|
|
102
107
|
type SetValues<TSet> = TSet extends Set<infer TValue> ? TValue : never;
|
|
103
108
|
|
|
104
|
-
export type { ButtonSnapshot, ColumnheaderSnapshot, ComboboxSnapshot, ContainerSnapshot, DialogSnapshot, ElementRole, ElementSnapshot, HeadingSnapshot, InputSnapshot, LinkSnapshot, MenuitemSnapshot, NodeRole, NodeSnapshot, OptionSnapshot, TabSnapshot, TextSnapshot };
|
|
109
|
+
export type { ButtonSnapshot, ColumnheaderSnapshot, ComboboxSnapshot, ContainerSnapshot, DialogSnapshot, ElementRole, ElementSnapshot, GroupSnapshot, HeadingSnapshot, InputSnapshot, LinkSnapshot, MenuitemSnapshot, NodeRole, NodeSnapshot, OptionSnapshot, TabSnapshot, TextSnapshot };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cronn/element-snapshot",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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": {
|