@cronn/element-snapshot 0.17.0 → 0.18.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.
Files changed (2) hide show
  1. package/dist/index.mjs +17 -17
  2. package/package.json +7 -7
package/dist/index.mjs CHANGED
@@ -154,7 +154,6 @@ var SemanticSnapshotTransformer = class {
154
154
  const { role, children } = normalizedSnapshot;
155
155
  return this.transformedSnapshot(role, children.length === 1 ? children.at(0) : children);
156
156
  }
157
- if (snapshot.role === "combobox") return this.simplifyComboboxSnapshot(snapshot);
158
157
  const { role, name, attributes, children } = normalizedSnapshot;
159
158
  return this.transformedSnapshot(role, {
160
159
  name: name.length === 0 ? void 0 : name,
@@ -162,27 +161,18 @@ var SemanticSnapshotTransformer = class {
162
161
  children: children.length === 0 ? void 0 : children
163
162
  });
164
163
  }
165
- normalizeElementSnapshot(snapshot, excludeAttributes = []) {
164
+ normalizeElementSnapshot(snapshot) {
166
165
  const normalizedName = snapshot.name ?? "";
167
- const filteredAttributes = this.filterAttributes(snapshot.attributes, excludeAttributes);
166
+ const transformedAttributes = this.transformAttributes(snapshot);
168
167
  const transformedChildren = this.transformSnapshots(snapshot.children);
169
168
  const nameEqualsChildren = transformedChildren.length === 1 && normalizedName === transformedChildren.at(0);
170
169
  return {
171
170
  role: snapshot.role,
172
171
  name: normalizedName,
173
- attributes: filteredAttributes,
172
+ attributes: transformedAttributes,
174
173
  children: nameEqualsChildren ? [] : transformedChildren
175
174
  };
176
175
  }
177
- simplifyComboboxSnapshot(snapshot) {
178
- const { role, name, attributes } = this.normalizeElementSnapshot(snapshot, ["options"]);
179
- const transformedOptions = snapshot.attributes.options.map((optionSnapshot) => this.simplifyElementSnapshot(optionSnapshot));
180
- return this.transformedSnapshot(role, {
181
- name,
182
- ...attributes,
183
- options: this.includeComboboxOptions && transformedOptions.length > 0 ? transformedOptions : void 0
184
- });
185
- }
186
176
  isEmpty(snapshot) {
187
177
  return isEmpty(snapshot.name) && isEmpty(snapshot.attributes) && isEmpty(snapshot.children);
188
178
  }
@@ -192,14 +182,24 @@ var SemanticSnapshotTransformer = class {
192
182
  hasOnlyChildren(snapshot) {
193
183
  return isEmpty(snapshot.name) && isEmpty(snapshot.attributes) && !isEmpty(snapshot.children);
194
184
  }
195
- filterAttributes(attributes, exclude) {
185
+ transformAttributes(snapshot) {
186
+ const { attributes } = snapshot;
196
187
  const filteredAttributes = {};
197
- Object.entries(attributes).forEach(([key, value]) => {
198
- if (value === void 0 && !exclude.includes(key)) return;
199
- filteredAttributes[key] = value;
188
+ Object.keys(attributes).forEach((attributeName) => {
189
+ const transformedAttribute = this.transformAttribute(attributeName, snapshot);
190
+ if (transformedAttribute === void 0) return;
191
+ filteredAttributes[attributeName] = transformedAttribute;
200
192
  });
201
193
  return filteredAttributes;
202
194
  }
195
+ transformAttribute(name, snapshot) {
196
+ const { role, attributes } = snapshot;
197
+ if (role === "combobox" && name === "options") {
198
+ const transformedOptions = attributes.options.map((optionSnapshot) => this.simplifyElementSnapshot(optionSnapshot));
199
+ return this.includeComboboxOptions && transformedOptions.length > 0 ? transformedOptions : void 0;
200
+ }
201
+ return attributes[name];
202
+ }
203
203
  transformedSnapshot(role, content) {
204
204
  return { [role]: content };
205
205
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cronn/element-snapshot",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "Element snapshots for Playwright",
5
5
  "bugs": {
6
6
  "url": "https://github.com/cronn/file-snapshots/issues"
@@ -41,29 +41,29 @@
41
41
  ],
42
42
  "dependencies": {
43
43
  "package-directory": "8.2.0",
44
- "@cronn/lib-file-snapshots": "1.1.0"
44
+ "@cronn/lib-file-snapshots": "1.1.1"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@arethetypeswrong/core": "0.18.2",
48
48
  "@playwright/test": "1.59.1",
49
49
  "@trivago/prettier-plugin-sort-imports": "6.0.2",
50
50
  "@types/node": "24.12.2",
51
- "@typescript/native-preview": "7.0.0-dev.20260406.1",
51
+ "@typescript/native-preview": "7.0.0-dev.20260413.1",
52
52
  "@vitest/coverage-v8": "4.1.4",
53
53
  "eslint": "10.2.0",
54
54
  "eslint-config-prettier": "10.1.8",
55
55
  "eslint-plugin-check-file": "3.3.1",
56
56
  "eslint-plugin-unused-imports": "4.4.1",
57
- "prettier": "3.8.1",
57
+ "prettier": "3.8.2",
58
58
  "publint": "0.3.18",
59
59
  "rimraf": "6.1.3",
60
60
  "tsdown": "0.21.7",
61
- "typescript-eslint": "8.58.0",
61
+ "typescript-eslint": "8.58.1",
62
62
  "vitest": "4.1.4",
63
- "@cronn/playwright-file-snapshots": "1.0.3",
63
+ "@cronn/playwright-file-snapshots": "1.0.4",
64
64
  "@cronn/shared-configs": "0.0.0",
65
65
  "@cronn/test-utils": "0.0.0",
66
- "@cronn/vitest-file-snapshots": "1.1.0"
66
+ "@cronn/vitest-file-snapshots": "1.1.1"
67
67
  },
68
68
  "peerDependencies": {
69
69
  "@playwright/test": "^1.55"