@cronn/element-snapshot 0.2.0 → 0.4.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 CHANGED
@@ -59,11 +59,24 @@ interface LinkAttributes {
59
59
  url?: string;
60
60
  }
61
61
 
62
+ interface MenuitemSnapshot extends GenericElementSnapshot<"menuitem", MenuitemAttributes> {
63
+ }
64
+ interface MenuitemAttributes extends LinkAttributes, DisableableAttributes {
65
+ }
66
+
62
67
  interface TabSnapshot extends GenericElementSnapshot<"tab", TabAttributes> {
63
68
  }
64
69
  interface TabAttributes extends DisableableAttributes, SelectableAttributes {
65
70
  }
66
71
 
72
+ interface ColumnheaderSnapshot extends GenericElementSnapshot<"columnheader", ColumnheaderAttributes> {
73
+ }
74
+ interface ColumnheaderAttributes {
75
+ sort?: SortAttribute;
76
+ }
77
+ declare const SORT_ATTRIBUTES: Set<"ascending" | "descending" | "other">;
78
+ type SortAttribute = SetValues<typeof SORT_ATTRIBUTES>;
79
+
67
80
  interface TextSnapshot {
68
81
  role: "text";
69
82
  name: string;
@@ -71,20 +84,21 @@ interface TextSnapshot {
71
84
 
72
85
  type SnapshotTargetElement = HTMLElement | SVGElement;
73
86
  type NodeRole = ElementRole | "text";
74
- type ElementRole = "heading" | "link" | "button" | "option" | "tab" | ContainerRole | InputRole | DialogRole;
87
+ type ElementRole = "heading" | "link" | "button" | "option" | "tab" | "menuitem" | "columnheader" | ContainerRole | InputRole | DialogRole;
75
88
  type NodeSnapshot = ElementSnapshot | TextSnapshot;
76
- type ElementSnapshot = ContainerSnapshot | HeadingSnapshot | LinkSnapshot | ButtonSnapshot | InputSnapshot | ComboboxSnapshot | OptionSnapshot | DialogSnapshot | TabSnapshot;
89
+ type ElementSnapshot = ContainerSnapshot | HeadingSnapshot | LinkSnapshot | ButtonSnapshot | InputSnapshot | ComboboxSnapshot | OptionSnapshot | DialogSnapshot | TabSnapshot | MenuitemSnapshot | ColumnheaderSnapshot;
77
90
  interface GenericElementSnapshot<TRole extends NodeRole = NodeRole, TAttributes = unknown> {
78
91
  role: TRole;
79
92
  name?: string;
80
93
  attributes?: TAttributes;
81
94
  children?: Array<NodeSnapshot>;
82
95
  }
96
+ type SetValues<TSet> = TSet extends Set<infer TValue> ? TValue : never;
83
97
 
84
- declare const CONTAINER_ROLES: readonly ["paragraph", "list", "listitem", "listbox", "article", "banner", "complementary", "contentinfo", "form", "main", "navigation", "region", "search", "term", "definition", "table", "grid", "rowgroup", "row", "columnheader", "rowheader", "cell", "gridcell", "alert", "menu", "menuitem", "tablist", "tabpanel"];
98
+ declare const CONTAINER_ROLES: Set<"paragraph" | "list" | "listitem" | "listbox" | "article" | "banner" | "complementary" | "contentinfo" | "form" | "main" | "navigation" | "region" | "search" | "term" | "definition" | "table" | "grid" | "rowgroup" | "row" | "rowheader" | "cell" | "gridcell" | "alert" | "menu" | "tablist" | "tabpanel">;
85
99
  interface ContainerSnapshot extends GenericElementSnapshot<ContainerRole> {
86
100
  }
87
- type ContainerRole = (typeof CONTAINER_ROLES)[number];
101
+ type ContainerRole = SetValues<typeof CONTAINER_ROLES>;
88
102
 
89
103
  declare function snapshotElement(element: SnapshotTargetElement): Array<NodeSnapshot>;
90
104
 
@@ -17,6 +17,12 @@
17
17
  return void 0;
18
18
  }
19
19
  }
20
+ function enumAttribute(value, supportedValues) {
21
+ if (value === null || !supportedValues.has(value)) {
22
+ return void 0;
23
+ }
24
+ return value;
25
+ }
20
26
  function resolveElementReference(element, attributeName) {
21
27
  const referenceId = element.getAttribute(attributeName);
22
28
  if (referenceId === null) {
@@ -66,9 +72,12 @@
66
72
  }
67
73
 
68
74
  // src/snapshots/state.ts
69
- function disableableAttributes(element) {
75
+ function disableableAttributes(element, ariaOnly = false) {
76
+ if (ariaOnly) {
77
+ return { disabled: booleanAttribute(element.ariaDisabled) };
78
+ }
70
79
  return {
71
- disabled: booleanAttribute(element.hasAttribute("disabled"))
80
+ disabled: booleanAttribute(element.hasAttribute("disabled")) ?? booleanAttribute(element.ariaDisabled)
72
81
  };
73
82
  }
74
83
  function selectableAttributes(element) {
@@ -104,7 +113,7 @@
104
113
  }
105
114
 
106
115
  // src/snapshots/container.ts
107
- var CONTAINER_ROLES = [
116
+ var CONTAINER_ROLES = /* @__PURE__ */ new Set([
108
117
  "paragraph",
109
118
  "list",
110
119
  "listitem",
@@ -124,16 +133,14 @@
124
133
  "grid",
125
134
  "rowgroup",
126
135
  "row",
127
- "columnheader",
128
136
  "rowheader",
129
137
  "cell",
130
138
  "gridcell",
131
139
  "alert",
132
140
  "menu",
133
- "menuitem",
134
141
  "tablist",
135
142
  "tabpanel"
136
- ];
143
+ ]);
137
144
  function snapshotContainer(role, element) {
138
145
  const children = snapshotChildren(element);
139
146
  return {
@@ -142,9 +149,8 @@
142
149
  children
143
150
  };
144
151
  }
145
- var CONTAINER_ROLES_SET = new Set(CONTAINER_ROLES);
146
152
  function isContainerRole(role) {
147
- return CONTAINER_ROLES_SET.has(role);
153
+ return CONTAINER_ROLES.has(role);
148
154
  }
149
155
 
150
156
  // src/snapshots/selector.ts
@@ -544,7 +550,23 @@
544
550
  return {
545
551
  role: "link",
546
552
  name: resolveAccessibleName(element),
547
- attributes: { url: stringAttribute(element.getAttribute("href")) },
553
+ attributes: linkAttributes(element),
554
+ children: snapshotChildren(element)
555
+ };
556
+ }
557
+ function linkAttributes(element) {
558
+ return { url: stringAttribute(element.getAttribute("href")) };
559
+ }
560
+
561
+ // src/snapshots/list.ts
562
+ function snapshotMenuitem(element) {
563
+ return {
564
+ role: "menuitem",
565
+ name: resolveAccessibleName(element),
566
+ attributes: {
567
+ ...linkAttributes(element),
568
+ ...disableableAttributes(element, true)
569
+ },
548
570
  children: snapshotChildren(element)
549
571
  };
550
572
  }
@@ -562,6 +584,19 @@
562
584
  };
563
585
  }
564
586
 
587
+ // src/snapshots/table.ts
588
+ var SORT_ATTRIBUTES = /* @__PURE__ */ new Set(["ascending", "descending", "other"]);
589
+ function snapshotColumnheader(element) {
590
+ return {
591
+ role: "columnheader",
592
+ name: resolveAccessibleName(element),
593
+ attributes: {
594
+ sort: enumAttribute(element.ariaSort, SORT_ATTRIBUTES)
595
+ },
596
+ children: snapshotChildren(element)
597
+ };
598
+ }
599
+
565
600
  // src/snapshots/element.ts
566
601
  var ROLE_SNAPSHOTS = {
567
602
  button: snapshotButton,
@@ -577,7 +612,9 @@
577
612
  textbox: snapshotInput,
578
613
  dialog: snapshotDialogWithRole("dialog"),
579
614
  alertdialog: snapshotDialogWithRole("alertdialog"),
580
- tab: snapshotTab
615
+ tab: snapshotTab,
616
+ menuitem: snapshotMenuitem,
617
+ columnheader: snapshotColumnheader
581
618
  };
582
619
  function snapshotElement(element) {
583
620
  return snapshotNodeRecursive(element);
package/dist/types.d.ts CHANGED
@@ -39,10 +39,10 @@ interface OptionAttributes {
39
39
  selected?: boolean;
40
40
  }
41
41
 
42
- declare const CONTAINER_ROLES: readonly ["paragraph", "list", "listitem", "listbox", "article", "banner", "complementary", "contentinfo", "form", "main", "navigation", "region", "search", "term", "definition", "table", "grid", "rowgroup", "row", "columnheader", "rowheader", "cell", "gridcell", "alert", "menu", "menuitem", "tablist", "tabpanel"];
42
+ declare const CONTAINER_ROLES: Set<"paragraph" | "list" | "listitem" | "listbox" | "article" | "banner" | "complementary" | "contentinfo" | "form" | "main" | "navigation" | "region" | "search" | "term" | "definition" | "table" | "grid" | "rowgroup" | "row" | "rowheader" | "cell" | "gridcell" | "alert" | "menu" | "tablist" | "tabpanel">;
43
43
  interface ContainerSnapshot extends GenericElementSnapshot<ContainerRole> {
44
44
  }
45
- type ContainerRole = (typeof CONTAINER_ROLES)[number];
45
+ type ContainerRole = SetValues<typeof CONTAINER_ROLES>;
46
46
 
47
47
  interface DialogSnapshot extends GenericElementSnapshot<DialogRole, DialogAttributes> {
48
48
  }
@@ -64,25 +64,39 @@ interface LinkAttributes {
64
64
  url?: string;
65
65
  }
66
66
 
67
+ interface MenuitemSnapshot extends GenericElementSnapshot<"menuitem", MenuitemAttributes> {
68
+ }
69
+ interface MenuitemAttributes extends LinkAttributes, DisableableAttributes {
70
+ }
71
+
67
72
  interface TabSnapshot extends GenericElementSnapshot<"tab", TabAttributes> {
68
73
  }
69
74
  interface TabAttributes extends DisableableAttributes, SelectableAttributes {
70
75
  }
71
76
 
77
+ interface ColumnheaderSnapshot extends GenericElementSnapshot<"columnheader", ColumnheaderAttributes> {
78
+ }
79
+ interface ColumnheaderAttributes {
80
+ sort?: SortAttribute;
81
+ }
82
+ declare const SORT_ATTRIBUTES: Set<"ascending" | "descending" | "other">;
83
+ type SortAttribute = SetValues<typeof SORT_ATTRIBUTES>;
84
+
72
85
  interface TextSnapshot {
73
86
  role: "text";
74
87
  name: string;
75
88
  }
76
89
 
77
90
  type NodeRole = ElementRole | "text";
78
- type ElementRole = "heading" | "link" | "button" | "option" | "tab" | ContainerRole | InputRole | DialogRole;
91
+ type ElementRole = "heading" | "link" | "button" | "option" | "tab" | "menuitem" | "columnheader" | ContainerRole | InputRole | DialogRole;
79
92
  type NodeSnapshot = ElementSnapshot | TextSnapshot;
80
- type ElementSnapshot = ContainerSnapshot | HeadingSnapshot | LinkSnapshot | ButtonSnapshot | InputSnapshot | ComboboxSnapshot | OptionSnapshot | DialogSnapshot | TabSnapshot;
93
+ type ElementSnapshot = ContainerSnapshot | HeadingSnapshot | LinkSnapshot | ButtonSnapshot | InputSnapshot | ComboboxSnapshot | OptionSnapshot | DialogSnapshot | TabSnapshot | MenuitemSnapshot | ColumnheaderSnapshot;
81
94
  interface GenericElementSnapshot<TRole extends NodeRole = NodeRole, TAttributes = unknown> {
82
95
  role: TRole;
83
96
  name?: string;
84
97
  attributes?: TAttributes;
85
98
  children?: Array<NodeSnapshot>;
86
99
  }
100
+ type SetValues<TSet> = TSet extends Set<infer TValue> ? TValue : never;
87
101
 
88
- export type { ElementSnapshot, NodeSnapshot, TextSnapshot };
102
+ export type { ButtonSnapshot, ColumnheaderSnapshot, ComboboxSnapshot, ContainerSnapshot, DialogSnapshot, ElementRole, ElementSnapshot, 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.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Element snapshots for Playwright",
5
5
  "author": "cronn",
6
6
  "license": "Apache-2.0",
@@ -29,14 +29,14 @@
29
29
  "dist"
30
30
  ],
31
31
  "devDependencies": {
32
- "@trivago/prettier-plugin-sort-imports": "5.2.2",
33
- "eslint": "9.39.0",
32
+ "@trivago/prettier-plugin-sort-imports": "6.0.0",
33
+ "eslint": "9.39.1",
34
34
  "eslint-config-prettier": "10.1.8",
35
35
  "eslint-plugin-unused-imports": "4.3.0",
36
36
  "prettier": "3.6.2",
37
37
  "tsup": "8.5.0",
38
38
  "typescript": "5.9.3",
39
- "typescript-eslint": "8.46.2",
39
+ "typescript-eslint": "8.46.3",
40
40
  "@cronn/shared-configs": "0.0.0"
41
41
  },
42
42
  "scripts": {