@cronn/element-snapshot 0.31.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.
@@ -451,7 +451,7 @@
451
451
  function resolveLabelName(element) {
452
452
  if (element.id !== null) {
453
453
  const referencedElement = element.ownerDocument.querySelector(attributeSelector("for", element.id));
454
- if (referencedElement !== null) return resolveAccessibleTextContent(referencedElement);
454
+ if (referencedElement !== null) return resolveAccessibleTextContent(referencedElement, [element]);
455
455
  }
456
456
  const closestLabel = element.closest("label");
457
457
  if (closestLabel !== null) return resolveAccessibleTextContent(closestLabel, [element]);
@@ -515,6 +515,11 @@
515
515
  };
516
516
  }
517
517
  //#endregion
518
+ //#region src/utils/array.ts
519
+ function unwrapSingleItem(items) {
520
+ return items.length === 1 ? items.at(0) : items;
521
+ }
522
+ //#endregion
518
523
  //#region src/browser/description.ts
519
524
  function discribableAttributes(element) {
520
525
  return { description: resolveDescription(element) };
@@ -600,8 +605,7 @@
600
605
  if (!(element instanceof HTMLSelectElement)) return resolveAccessibleTextContent(element);
601
606
  const selectedLabels = Array.from(element.selectedOptions).map((option) => option.label);
602
607
  if (selectedLabels.length === 0) return;
603
- if (selectedLabels.length === 1) return selectedLabels.at(0);
604
- return selectedLabels;
608
+ return unwrapSingleItem(selectedLabels);
605
609
  }
606
610
  function snapshotOptions(element) {
607
611
  const optionsContainer = resolveOptionsContainer(element);
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, children.length === 1 ? children.at(0) : children);
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.length === 0 ? void 0 : 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
- const transformedSnapshots = this.filterSnapshots(snapshots).map(this.transformSnapshotRecursive);
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.31.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": {