@simplysf/simply-utam-core 0.1.3 → 0.3.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/README.md +72 -14
- package/lib/forceignore/forceignore-manager.d.ts +30 -0
- package/lib/forceignore/forceignore-manager.js +30 -13
- package/lib/forceignore/forceignore-manager.js.map +1 -1
- package/lib/forceignore/index.d.ts +1 -1
- package/lib/forceignore/index.js +1 -1
- package/lib/forceignore/index.js.map +1 -1
- package/lib/gitignore/gitignore-manager.d.ts +64 -0
- package/lib/gitignore/gitignore-manager.js +96 -0
- package/lib/gitignore/gitignore-manager.js.map +1 -0
- package/lib/gitignore/index.d.ts +1 -0
- package/lib/gitignore/index.js +17 -0
- package/lib/gitignore/index.js.map +1 -0
- package/lib/index.d.ts +3 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/namespaces/namespace-map.d.ts +18 -0
- package/lib/namespaces/namespace-map.js +75 -0
- package/lib/namespaces/namespace-map.js.map +1 -0
- package/lib/namespaces/namespace-rewriter.js +2 -47
- package/lib/namespaces/namespace-rewriter.js.map +1 -1
- package/lib/path-utils.d.ts +8 -0
- package/lib/path-utils.js +10 -0
- package/lib/path-utils.js.map +1 -1
- package/lib/scaffold/project-scaffolder.d.ts +75 -1
- package/lib/scaffold/project-scaffolder.js +267 -19
- package/lib/scaffold/project-scaffolder.js.map +1 -1
- package/lib/snapshot/capture.d.ts +56 -0
- package/lib/snapshot/capture.js +115 -0
- package/lib/snapshot/capture.js.map +1 -0
- package/lib/snapshot/console.d.ts +25 -0
- package/lib/snapshot/console.js +74 -0
- package/lib/snapshot/console.js.map +1 -0
- package/lib/snapshot/describe.d.ts +27 -0
- package/lib/snapshot/describe.js +76 -0
- package/lib/snapshot/describe.js.map +1 -0
- package/lib/snapshot/files.d.ts +85 -0
- package/lib/snapshot/files.js +185 -0
- package/lib/snapshot/files.js.map +1 -0
- package/lib/snapshot/find.d.ts +36 -0
- package/lib/snapshot/find.js +186 -0
- package/lib/snapshot/find.js.map +1 -0
- package/lib/snapshot/format.d.ts +96 -0
- package/lib/snapshot/format.js +100 -0
- package/lib/snapshot/format.js.map +1 -0
- package/lib/snapshot/header.d.ts +38 -0
- package/lib/snapshot/header.js +120 -0
- package/lib/snapshot/header.js.map +1 -0
- package/lib/snapshot/index.d.ts +13 -0
- package/lib/snapshot/index.js +28 -0
- package/lib/snapshot/index.js.map +1 -0
- package/lib/snapshot/locate.d.ts +61 -0
- package/lib/snapshot/locate.js +110 -0
- package/lib/snapshot/locate.js.map +1 -0
- package/lib/snapshot/lookup.d.ts +53 -0
- package/lib/snapshot/lookup.js +188 -0
- package/lib/snapshot/lookup.js.map +1 -0
- package/lib/snapshot/page-object-index.d.ts +149 -0
- package/lib/snapshot/page-object-index.js +806 -0
- package/lib/snapshot/page-object-index.js.map +1 -0
- package/lib/snapshot/page-object-packages.d.ts +41 -0
- package/lib/snapshot/page-object-packages.js +115 -0
- package/lib/snapshot/page-object-packages.js.map +1 -0
- package/lib/snapshot/path.d.ts +102 -0
- package/lib/snapshot/path.js +381 -0
- package/lib/snapshot/path.js.map +1 -0
- package/lib/snapshot/query-result.d.ts +20 -0
- package/lib/snapshot/query-result.js +32 -0
- package/lib/snapshot/query-result.js.map +1 -0
- package/lib/snapshot/selector.d.ts +103 -0
- package/lib/snapshot/selector.js +280 -0
- package/lib/snapshot/selector.js.map +1 -0
- package/lib/snapshot/tree.d.ts +76 -0
- package/lib/snapshot/tree.js +201 -0
- package/lib/snapshot/tree.js.map +1 -0
- package/lib/snapshot/walker.js +532 -0
- package/package.json +11 -3
- package/templates/dom-snapshot.steps.mjs +34 -0
- package/templates/wdio.conf.mjs +81 -4
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2026, SimplySF.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// The DOM snapshot walker. Every way of capturing a snapshot sends this file's function to the page
|
|
18
|
+
// as text and runs `(<function>)(options)`, so it must stay one function declaration with no imports
|
|
19
|
+
// and no references to anything outside it. Core reads this file as text; nothing compiles it.
|
|
20
|
+
// It returns the snapshot as a JSON string.
|
|
21
|
+
function domSnapshotWalker(input) {
|
|
22
|
+
'use strict';
|
|
23
|
+
|
|
24
|
+
const options = input || {};
|
|
25
|
+
const mask = options.mask || 'labels';
|
|
26
|
+
const maxNodes = options.maxNodes ?? 20000;
|
|
27
|
+
const maxHiddenNodes = options.maxHiddenNodes ?? 5000;
|
|
28
|
+
const timeBudgetMs = options.timeBudgetMs ?? 3000;
|
|
29
|
+
const root = document.documentElement;
|
|
30
|
+
// jsdom has no `checkVisibility` and no layout, so tests pass both in.
|
|
31
|
+
const isVisibleNative =
|
|
32
|
+
options.checkVisibility ||
|
|
33
|
+
(typeof Element.prototype.checkVisibility === 'function'
|
|
34
|
+
? (el) => el.checkVisibility({ visibilityProperty: true, opacityProperty: true })
|
|
35
|
+
: null);
|
|
36
|
+
const getRect = options.getRect || ((el) => el.getBoundingClientRect());
|
|
37
|
+
// 'none' (document order), 'auto' (the active Lightning page or console tab), or a CSS selector.
|
|
38
|
+
const focus = options.focus || 'none';
|
|
39
|
+
|
|
40
|
+
// ---- Rules as data -------------------------------------------------------------------------
|
|
41
|
+
|
|
42
|
+
const KEPT_ATTRS = [
|
|
43
|
+
'id',
|
|
44
|
+
'class',
|
|
45
|
+
'name',
|
|
46
|
+
'type',
|
|
47
|
+
'role',
|
|
48
|
+
'slot',
|
|
49
|
+
'aria-hidden',
|
|
50
|
+
'title',
|
|
51
|
+
'aria-label',
|
|
52
|
+
'placeholder',
|
|
53
|
+
'alt',
|
|
54
|
+
'value',
|
|
55
|
+
];
|
|
56
|
+
const KEEP_BY_ATTR = ['name', 'type', 'role', 'slot', 'title', 'aria-label', 'placeholder', 'alt'];
|
|
57
|
+
const KEEP_TAGS = ['a', 'button', 'input', 'select', 'textarea', 'label', 'option', 'iframe'];
|
|
58
|
+
const DROP_TAGS = ['head', 'script', 'style', 'link', 'meta', 'template', 'noscript'];
|
|
59
|
+
const HIDDEN_KEEP_ATTRS = ['name'];
|
|
60
|
+
const LABEL_SELECTORS = [
|
|
61
|
+
'label',
|
|
62
|
+
'legend',
|
|
63
|
+
'button',
|
|
64
|
+
'option',
|
|
65
|
+
'th[scope="col"]',
|
|
66
|
+
'h2',
|
|
67
|
+
'h3',
|
|
68
|
+
'h4',
|
|
69
|
+
'h5',
|
|
70
|
+
'h6',
|
|
71
|
+
'[role="button"]',
|
|
72
|
+
'[role="columnheader"]',
|
|
73
|
+
'[role="tab"]',
|
|
74
|
+
'.slds-form-element__label',
|
|
75
|
+
'.test-id__field-label',
|
|
76
|
+
'.slds-card__header-title',
|
|
77
|
+
'.slds-text-title',
|
|
78
|
+
'records-entity-label',
|
|
79
|
+
];
|
|
80
|
+
// Never label-like, even under a label-like ancestor: Lightning shows record values in these.
|
|
81
|
+
const NEVER_LABEL_SELECTORS = [
|
|
82
|
+
'a:not([role="tab"]):not([role="button"])',
|
|
83
|
+
'h1',
|
|
84
|
+
'[role="option"]',
|
|
85
|
+
'[role="menuitem"]',
|
|
86
|
+
'th:not([scope="col"])',
|
|
87
|
+
];
|
|
88
|
+
const NEVER_LABEL_TAG_PREFIXES = ['lightning-formatted-'];
|
|
89
|
+
const ALWAYS_MASK_WITHIN = ['.tabBarItems', 'tbody', '[role="row"]:not(thead *)'];
|
|
90
|
+
const CONTROL_TAGS = ['button', 'input', 'select', 'textarea'];
|
|
91
|
+
const CONTROL_ROLES = ['button', 'tab', 'checkbox', 'combobox'];
|
|
92
|
+
// Accessible names: masked in `labels` mode, kept on controls in `aria` mode. Lightning builds many
|
|
93
|
+
// from the record ("Show more actions for <record>"), and repeats them in assistive text.
|
|
94
|
+
const NAME_ATTRS = ['title', 'aria-label', 'placeholder', 'alt'];
|
|
95
|
+
const ASSISTIVE_TEXT_SELECTORS = ['.slds-assistive-text', '.assistiveText'];
|
|
96
|
+
// Headings in a dialog are never label-like in `labels` mode: a modal's title names its record.
|
|
97
|
+
const HEADING_SELECTORS = ['h2', 'h3', 'h4', 'h5', 'h6'];
|
|
98
|
+
const DIALOG_SELECTORS = ['[role="dialog"]', '[role="alertdialog"]', '.slds-modal'];
|
|
99
|
+
const VALUE_ATTRS = ['value', 'data-value', 'data-text', 'data-label-value'];
|
|
100
|
+
const FOCUS_SELECTORS = ['section.tabContent.oneConsoleTab', '.oneContent.lafPageHost', '[role="main"]', 'main'];
|
|
101
|
+
|
|
102
|
+
// ---- State ---------------------------------------------------------------------------------
|
|
103
|
+
|
|
104
|
+
const start = performance.now();
|
|
105
|
+
const reasons = [];
|
|
106
|
+
let visibleCount = 0;
|
|
107
|
+
let hiddenCount = 0;
|
|
108
|
+
let visibleFull = false;
|
|
109
|
+
let hiddenFull = false;
|
|
110
|
+
let outOfTime = false;
|
|
111
|
+
const hiddenQueue = [];
|
|
112
|
+
// Elements read by hasVisibleDescendant, and its answer for each element it has searched.
|
|
113
|
+
let checkedCount = 0;
|
|
114
|
+
const visibleDescendant = new WeakMap();
|
|
115
|
+
|
|
116
|
+
function addReason(reason) {
|
|
117
|
+
if (!reasons.includes(reason)) reasons.push(reason);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function checkTime() {
|
|
121
|
+
if (!outOfTime && performance.now() - start > timeBudgetMs) {
|
|
122
|
+
outOfTime = true;
|
|
123
|
+
addReason('time');
|
|
124
|
+
}
|
|
125
|
+
return outOfTime;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ---- Masking -------------------------------------------------------------------------------
|
|
129
|
+
|
|
130
|
+
function maskValue(value) {
|
|
131
|
+
return '•' + value.length;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function scrub(value) {
|
|
135
|
+
return value
|
|
136
|
+
.replace(/[\w.+-]+@[\w-]+(\.[\w-]+)+/g, '•email')
|
|
137
|
+
.replace(/\b(?=[a-zA-Z0-9]*\d)[a-zA-Z0-9]{15}(?:[a-zA-Z0-9]{3})?\b/g, '•id');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function matchesAny(el, selectors) {
|
|
141
|
+
for (const selector of selectors) {
|
|
142
|
+
try {
|
|
143
|
+
if (el.matches(selector)) return true;
|
|
144
|
+
} catch {
|
|
145
|
+
// An unsupported selector in the list must not stop the walk.
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function isNeverLabel(el) {
|
|
152
|
+
const tag = el.localName;
|
|
153
|
+
for (const prefix of NEVER_LABEL_TAG_PREFIXES) if (tag.startsWith(prefix)) return true;
|
|
154
|
+
return matchesAny(el, NEVER_LABEL_SELECTORS);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// In `labels` mode, text that names a control or a dialog's record: assistive text in a control,
|
|
158
|
+
// and headings in a dialog.
|
|
159
|
+
function isAccessibleName(el) {
|
|
160
|
+
if (mask !== 'labels') return false;
|
|
161
|
+
if (matchesAny(el, ASSISTIVE_TEXT_SELECTORS)) return isInControl(el);
|
|
162
|
+
return matchesAny(el, HEADING_SELECTORS) && isInDialog(el);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// The element or an ancestor within two levels, in the same tree, is a control.
|
|
166
|
+
function isInControl(el) {
|
|
167
|
+
let current = el;
|
|
168
|
+
for (let level = 0; level < 3 && current; level++) {
|
|
169
|
+
if (isControl(current)) return true;
|
|
170
|
+
current = current.parentElement;
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// The element or any ancestor, crossing shadow hosts, is a dialog.
|
|
176
|
+
function isInDialog(el) {
|
|
177
|
+
for (let current = el; current; current = current.parentElement || current.parentNode?.host) {
|
|
178
|
+
if (matchesAny(current, DIALOG_SELECTORS)) return true;
|
|
179
|
+
}
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// The element or an ancestor within two levels, in the same tree, matches the label list, and
|
|
184
|
+
// none of those levels is a never-label element or an accessible name.
|
|
185
|
+
function isLabelLike(el) {
|
|
186
|
+
let current = el;
|
|
187
|
+
let labelLike = false;
|
|
188
|
+
for (let level = 0; level < 3 && current; level++) {
|
|
189
|
+
if (isNeverLabel(current) || isAccessibleName(current)) return false;
|
|
190
|
+
if (!labelLike && matchesAny(current, LABEL_SELECTORS)) labelLike = true;
|
|
191
|
+
current = current.parentElement;
|
|
192
|
+
}
|
|
193
|
+
return labelLike;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function isControl(el) {
|
|
197
|
+
if (CONTROL_TAGS.includes(el.localName)) return true;
|
|
198
|
+
const role = el.getAttribute('role');
|
|
199
|
+
return role !== null && CONTROL_ROLES.includes(role);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function isValueAttr(name) {
|
|
203
|
+
return VALUE_ATTRS.includes(name) || (name.startsWith('data-') && name.endsWith('-value'));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function maskText(text, el, inMaskZone) {
|
|
207
|
+
if (mask === 'full') return text;
|
|
208
|
+
if (mask === 'structure' || inMaskZone) return maskValue(text);
|
|
209
|
+
return isLabelLike(el) ? scrub(text) : maskValue(text);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function maskAttr(name, value, el, inMaskZone) {
|
|
213
|
+
if (mask === 'full') return value;
|
|
214
|
+
if (isValueAttr(name)) return maskValue(value);
|
|
215
|
+
if (NAME_ATTRS.includes(name)) {
|
|
216
|
+
if (mask !== 'aria' || inMaskZone || !isControl(el)) return maskValue(value);
|
|
217
|
+
}
|
|
218
|
+
return scrub(value);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// ---- Element facts -------------------------------------------------------------------------
|
|
222
|
+
|
|
223
|
+
function isGeneratedId(id) {
|
|
224
|
+
return /-\d+$/.test(id) || /^\d+:\d+/.test(id) || /;a$/.test(id);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Text nodes directly under `parent`: an element's light children, or a shadow root's.
|
|
228
|
+
function ownText(parent) {
|
|
229
|
+
let text = '';
|
|
230
|
+
for (const child of parent.childNodes) {
|
|
231
|
+
if (child.nodeType === 3) text += ' ' + child.nodeValue;
|
|
232
|
+
}
|
|
233
|
+
text = text.replace(/\s+/g, ' ').trim();
|
|
234
|
+
return text.length > 80 ? text.slice(0, 80) : text;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function shadowMode(shadowRoot) {
|
|
238
|
+
if (shadowRoot.synthetic === true) return 'synthetic';
|
|
239
|
+
if (Object.prototype.toString.call(shadowRoot) === '[object ShadowRoot]' && shadowRoot.synthetic === undefined) {
|
|
240
|
+
return 'native';
|
|
241
|
+
}
|
|
242
|
+
return 'unknown';
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Hidden, judged only where the parent is visible.
|
|
246
|
+
function isHidden(el, tag) {
|
|
247
|
+
// An option has no box of its own in a closed select; it's as visible as the select.
|
|
248
|
+
if (tag === 'option' || tag === 'optgroup') return false;
|
|
249
|
+
// `checkVisibility` is false for `display: contents`, whose children still render.
|
|
250
|
+
const style = getComputedStyle(el);
|
|
251
|
+
if (style.display === 'contents') return false;
|
|
252
|
+
const hidden = isVisibleNative
|
|
253
|
+
? !isVisibleNative(el)
|
|
254
|
+
: style.display === 'none' || style.visibility === 'hidden' || style.opacity === '0';
|
|
255
|
+
// `visibility` is inherited but can be overridden: a descendant set back to `visible` still
|
|
256
|
+
// renders. Such an element isn't the top of a hidden subtree; its children are judged on their own.
|
|
257
|
+
if (hidden && hiddenByVisibilityOnly(style) && hasVisibleDescendant(el)) return false;
|
|
258
|
+
return hidden;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function hiddenByVisibilityOnly(style) {
|
|
262
|
+
return style.visibility !== 'visible' && style.display !== 'none' && style.opacity !== '0';
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// A light or shadow descendant whose own `visibility` is `visible`, under no `display: none` or
|
|
266
|
+
// `opacity: 0`. Each element's answer is kept, so nested `visibility: hidden` levels don't search
|
|
267
|
+
// the same subtree again. The search stops at the time budget, and the elements it reads count
|
|
268
|
+
// against maxNodes; cut short, it answers no, so the element stays hidden.
|
|
269
|
+
function hasVisibleDescendant(el) {
|
|
270
|
+
if (visibleDescendant.has(el)) return visibleDescendant.get(el);
|
|
271
|
+
let found = false;
|
|
272
|
+
for (const child of [...el.children, ...(el.shadowRoot ? el.shadowRoot.children : [])]) {
|
|
273
|
+
if (checkTime()) break;
|
|
274
|
+
if (checkedCount >= maxNodes) {
|
|
275
|
+
addReason('nodes');
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
checkedCount++;
|
|
279
|
+
const style = getComputedStyle(child);
|
|
280
|
+
if (style.display === 'none' || style.opacity === '0') continue;
|
|
281
|
+
if (style.visibility === 'visible' || hasVisibleDescendant(child)) {
|
|
282
|
+
found = true;
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
visibleDescendant.set(el, found);
|
|
287
|
+
return found;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function shouldKeep(el, tag, inHidden) {
|
|
291
|
+
// The walk's root and `body` are always kept, so the snapshot has one root node.
|
|
292
|
+
if (el === root || tag === 'body') return true;
|
|
293
|
+
if (el.shadowRoot) return true;
|
|
294
|
+
if (tag.includes('-')) return true;
|
|
295
|
+
const hasData = el.getAttributeNames().some((name) => name.startsWith('data-'));
|
|
296
|
+
if (inHidden) {
|
|
297
|
+
return hasData || HIDDEN_KEEP_ATTRS.some((name) => el.hasAttribute(name)) || ownText(el) !== '';
|
|
298
|
+
}
|
|
299
|
+
if (KEEP_TAGS.includes(tag) || tag === 'svg') return true;
|
|
300
|
+
if (hasData) return true;
|
|
301
|
+
if (KEEP_BY_ATTR.some((name) => el.hasAttribute(name))) return true;
|
|
302
|
+
const id = el.getAttribute('id');
|
|
303
|
+
if (id && !isGeneratedId(id)) return true;
|
|
304
|
+
return ownText(el) !== '';
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function makeNode(el, tag, address, inHidden, inMaskZone) {
|
|
308
|
+
const node = { address, tag };
|
|
309
|
+
const attrs = {};
|
|
310
|
+
let hasAttrs = false;
|
|
311
|
+
for (const name of el.getAttributeNames()) {
|
|
312
|
+
if (!KEPT_ATTRS.includes(name) && !name.startsWith('data-')) continue;
|
|
313
|
+
const value = el.getAttribute(name);
|
|
314
|
+
if (name === 'id' && isGeneratedId(value)) continue;
|
|
315
|
+
attrs[name] = maskAttr(name, value, el, inMaskZone);
|
|
316
|
+
hasAttrs = true;
|
|
317
|
+
}
|
|
318
|
+
if (hasAttrs) node.attrs = attrs;
|
|
319
|
+
const text = ownText(el);
|
|
320
|
+
if (text !== '') node.text = maskText(text, el, inMaskZone);
|
|
321
|
+
if (!inHidden) {
|
|
322
|
+
const rect = getRect(el);
|
|
323
|
+
node.rect = [Math.round(rect.x), Math.round(rect.y), Math.round(rect.width), Math.round(rect.height)];
|
|
324
|
+
}
|
|
325
|
+
if (tag === 'iframe') {
|
|
326
|
+
const src = el.getAttribute('src');
|
|
327
|
+
if (src) node.src = mask === 'full' ? src : scrub(src.split('?')[0].split('#')[0]);
|
|
328
|
+
node.notCaptured = true;
|
|
329
|
+
}
|
|
330
|
+
return node;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// ---- Focus ---------------------------------------------------------------------------------
|
|
334
|
+
|
|
335
|
+
// Set when a focus element is walked first: the element, the elements from it up to the root
|
|
336
|
+
// (crossing shadow hosts), and the nodes its walk produced, spliced in when the main walk gets there.
|
|
337
|
+
let focusEl = null;
|
|
338
|
+
let focusPath = null;
|
|
339
|
+
let focusOut = null;
|
|
340
|
+
let focusAddress = null;
|
|
341
|
+
|
|
342
|
+
function findFocus() {
|
|
343
|
+
if (focus === 'none') return null;
|
|
344
|
+
const selectors = focus === 'auto' ? FOCUS_SELECTORS : [focus];
|
|
345
|
+
for (const selector of selectors) {
|
|
346
|
+
let matches;
|
|
347
|
+
try {
|
|
348
|
+
matches = document.querySelectorAll(selector);
|
|
349
|
+
} catch {
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
for (const el of matches) {
|
|
353
|
+
if (el !== root && (!isVisibleNative || isVisibleNative(el))) return el;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// The address `el` gets in the main walk, whether a mask zone covers it, and its ancestor chain.
|
|
360
|
+
function locate(el) {
|
|
361
|
+
const segments = [];
|
|
362
|
+
const path = new Set([el]);
|
|
363
|
+
let zone = false;
|
|
364
|
+
let current = el;
|
|
365
|
+
while (current !== root) {
|
|
366
|
+
const parent = current.parentElement;
|
|
367
|
+
if (parent) {
|
|
368
|
+
segments.unshift(String(Array.prototype.indexOf.call(parent.children, current)));
|
|
369
|
+
current = parent;
|
|
370
|
+
} else {
|
|
371
|
+
const shadowRoot = current.parentNode;
|
|
372
|
+
if (!shadowRoot || !shadowRoot.host) return null;
|
|
373
|
+
segments.unshift('s.' + Array.prototype.indexOf.call(shadowRoot.children, current));
|
|
374
|
+
current = shadowRoot.host;
|
|
375
|
+
}
|
|
376
|
+
path.add(current);
|
|
377
|
+
if (current !== root && matchesAny(current, ALWAYS_MASK_WITHIN)) zone = true;
|
|
378
|
+
}
|
|
379
|
+
return { address: ['0', ...segments].join('.'), path, zone };
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// ---- Walk ----------------------------------------------------------------------------------
|
|
383
|
+
|
|
384
|
+
// Visit `el`, adding its node (or, when pruned, its kept descendants) to `out`.
|
|
385
|
+
function visit(el, address, out, inHidden, inMaskZone) {
|
|
386
|
+
if (el === focusEl && focusOut) {
|
|
387
|
+
for (const node of focusOut) out.push(node);
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
// The focus element's ancestors are always walked, so its nodes have somewhere to go; so are the
|
|
391
|
+
// root and `body`, so the snapshot always has its root. Their descendants can still be cut.
|
|
392
|
+
const always = el === root || el === document.body;
|
|
393
|
+
const onFocusPath = always || (focusOut !== null && focusPath.has(el));
|
|
394
|
+
if (checkTime() && !onFocusPath) return;
|
|
395
|
+
if (inHidden ? hiddenFull : visibleFull && !onFocusPath) return;
|
|
396
|
+
const tag = el.localName;
|
|
397
|
+
if (DROP_TAGS.includes(tag)) return;
|
|
398
|
+
const zone = inMaskZone || matchesAny(el, ALWAYS_MASK_WITHIN);
|
|
399
|
+
|
|
400
|
+
// The top of a hidden subtree: kept while the hidden budget lasts, and walked after the visible tree.
|
|
401
|
+
if (!inHidden && isHidden(el, tag)) {
|
|
402
|
+
if (hiddenCount >= maxHiddenNodes && !always) {
|
|
403
|
+
hiddenFull = true;
|
|
404
|
+
addReason('hiddenNodes');
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
const node = makeNode(el, tag, address, true, zone);
|
|
408
|
+
node.hidden = true;
|
|
409
|
+
out.push(node);
|
|
410
|
+
hiddenCount++;
|
|
411
|
+
hiddenQueue.push({ el, address, node, zone });
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
let node = null;
|
|
416
|
+
if (shouldKeep(el, tag, inHidden)) {
|
|
417
|
+
if (inHidden) {
|
|
418
|
+
if (hiddenCount >= maxHiddenNodes) {
|
|
419
|
+
hiddenFull = true;
|
|
420
|
+
addReason('hiddenNodes');
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
hiddenCount++;
|
|
424
|
+
} else {
|
|
425
|
+
if (visibleCount >= maxNodes && !onFocusPath) {
|
|
426
|
+
visibleFull = true;
|
|
427
|
+
addReason('nodes');
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
visibleCount++;
|
|
431
|
+
}
|
|
432
|
+
node = makeNode(el, tag, address, inHidden, zone);
|
|
433
|
+
out.push(node);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
if (tag === 'svg') return;
|
|
437
|
+
walkTrees(el, address, node, node ? null : out, inHidden, zone);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// Walk an element's light children and its shadow root. A kept element gets its own `children`
|
|
441
|
+
// and `shadow`; a pruned one passes its light children up to `out`.
|
|
442
|
+
function walkTrees(el, address, node, out, inHidden, zone) {
|
|
443
|
+
const lightChildren = node ? [] : out;
|
|
444
|
+
let index = 0;
|
|
445
|
+
for (const child of el.children) {
|
|
446
|
+
visit(child, address + '.' + index, lightChildren, inHidden, zone);
|
|
447
|
+
index++;
|
|
448
|
+
}
|
|
449
|
+
if (node && lightChildren.length > 0) node.children = lightChildren;
|
|
450
|
+
|
|
451
|
+
const shadowRoot = el.shadowRoot;
|
|
452
|
+
// shouldKeep keeps every element with a shadow root, so `node` is set here.
|
|
453
|
+
if (shadowRoot && node) {
|
|
454
|
+
const shadowChildren = [];
|
|
455
|
+
let shadowIndex = 0;
|
|
456
|
+
for (const child of shadowRoot.children) {
|
|
457
|
+
visit(child, address + '.s.' + shadowIndex, shadowChildren, inHidden, zone);
|
|
458
|
+
shadowIndex++;
|
|
459
|
+
}
|
|
460
|
+
node.shadow = { mode: shadowMode(shadowRoot), children: shadowChildren };
|
|
461
|
+
// Components like `lightning-formatted-text` render their text straight into the shadow
|
|
462
|
+
// root, with no element around it. It's masked by the rules for the host.
|
|
463
|
+
const shadowText = ownText(shadowRoot);
|
|
464
|
+
if (shadowText !== '') node.shadow.text = maskText(shadowText, el, zone);
|
|
465
|
+
} else if (node && looksClosed(el, node)) {
|
|
466
|
+
// A closed shadow root isn't visible through `shadowRoot`, to the walker or to UTAM.
|
|
467
|
+
node.shadow = { mode: 'unreadable', children: [] };
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// A defined custom element that takes up space but has no readable shadow root, no children and
|
|
472
|
+
// no text of its own: most likely it renders into a closed shadow root.
|
|
473
|
+
function looksClosed(el, node) {
|
|
474
|
+
if (!node.tag.includes('-') || el.children.length > 0 || node.text !== undefined) return false;
|
|
475
|
+
if (!node.rect || node.rect[2] === 0 || node.rect[3] === 0) return false;
|
|
476
|
+
return typeof customElements !== 'undefined' && customElements.get(node.tag) !== undefined;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
const found = findFocus();
|
|
480
|
+
if (found) {
|
|
481
|
+
const located = locate(found);
|
|
482
|
+
if (located) {
|
|
483
|
+
focusEl = found;
|
|
484
|
+
focusPath = located.path;
|
|
485
|
+
focusAddress = located.address;
|
|
486
|
+
const out = [];
|
|
487
|
+
visit(focusEl, located.address, out, false, located.zone || matchesAny(focusEl, ALWAYS_MASK_WITHIN));
|
|
488
|
+
focusOut = out;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
const rootChildren = [];
|
|
493
|
+
visit(root, '0', rootChildren, false, false);
|
|
494
|
+
|
|
495
|
+
for (let i = 0; i < hiddenQueue.length; i++) {
|
|
496
|
+
if (checkTime() || hiddenFull) break;
|
|
497
|
+
const { el, address, node, zone } = hiddenQueue[i];
|
|
498
|
+
walkTrees(el, address, node, null, true, zone);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// ---- Metadata ------------------------------------------------------------------------------
|
|
502
|
+
|
|
503
|
+
function maskUrl(href) {
|
|
504
|
+
if (mask === 'full') return href;
|
|
505
|
+
return scrub(href.split('?')[0].split('#')[0]);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function maskTitle(title) {
|
|
509
|
+
if (mask === 'full') return title;
|
|
510
|
+
const parts = title.split('|').map((part) => part.trim());
|
|
511
|
+
return parts.map((part, i) => (i === parts.length - 1 ? part : maskValue(part))).join(' | ');
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
const meta = {
|
|
515
|
+
capturedAt: new Date().toISOString(),
|
|
516
|
+
trigger: options.trigger || 'manual',
|
|
517
|
+
url: maskUrl(location.href),
|
|
518
|
+
title: maskTitle(document.title),
|
|
519
|
+
viewport: [window.innerWidth, window.innerHeight],
|
|
520
|
+
};
|
|
521
|
+
if (options.label) meta.label = options.label;
|
|
522
|
+
meta.mask = mask;
|
|
523
|
+
meta.truncated = reasons.length > 0 ? { reasons } : null;
|
|
524
|
+
if (focusAddress) meta.focus = focusAddress;
|
|
525
|
+
|
|
526
|
+
return JSON.stringify({
|
|
527
|
+
format: 'simply-utam-dom-snapshot',
|
|
528
|
+
version: 1,
|
|
529
|
+
meta,
|
|
530
|
+
root: rootChildren[0] || null,
|
|
531
|
+
});
|
|
532
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysf/simply-utam-core",
|
|
3
3
|
"description": "Org authentication, Lightning navigation, and debugging helpers for UTAM UI tests against Salesforce",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"author": "@ClayChipps",
|
|
6
6
|
"homepage": "https://github.com/SimplySF/simply-utam",
|
|
7
7
|
"bugs": "https://github.com/SimplySF/simply-utam/issues",
|
|
@@ -67,10 +67,14 @@
|
|
|
67
67
|
"@cucumber/gherkin": "^42.0.1",
|
|
68
68
|
"@cucumber/messages": "^34.2.1",
|
|
69
69
|
"@salesforce/core": "^9.3.6",
|
|
70
|
+
"css-select": "^5.2.2",
|
|
70
71
|
"prettier": "^3.9.10"
|
|
71
72
|
},
|
|
72
73
|
"devDependencies": {
|
|
74
|
+
"@lwc/synthetic-shadow": "9.4.3",
|
|
75
|
+
"@types/jsdom": "^30.0.0",
|
|
73
76
|
"@vitest/coverage-v8": "^4.1.10",
|
|
77
|
+
"jsdom": "^30.1.3",
|
|
74
78
|
"vitest": "^4.1.10"
|
|
75
79
|
},
|
|
76
80
|
"publishConfig": {
|
|
@@ -95,9 +99,10 @@
|
|
|
95
99
|
]
|
|
96
100
|
},
|
|
97
101
|
"compile": {
|
|
98
|
-
"command": "tsc -p . --pretty --incremental",
|
|
102
|
+
"command": "tsc -p . --pretty --incremental && node -e \"require('node:fs').cpSync('src/snapshot/walker.js', 'lib/snapshot/walker.js')\"",
|
|
99
103
|
"files": [
|
|
100
104
|
"src/**/*.ts",
|
|
105
|
+
"src/**/*.js",
|
|
101
106
|
"**/tsconfig.json",
|
|
102
107
|
"../../tsconfig.json"
|
|
103
108
|
],
|
|
@@ -111,6 +116,7 @@
|
|
|
111
116
|
"command": "prettier --write \"+(src|test)/**/*.+(ts|js|json)\"",
|
|
112
117
|
"files": [
|
|
113
118
|
"src/**/*.ts",
|
|
119
|
+
"src/**/*.js",
|
|
114
120
|
"test/**/*.ts",
|
|
115
121
|
".prettier*"
|
|
116
122
|
],
|
|
@@ -120,6 +126,7 @@
|
|
|
120
126
|
"command": "eslint src test --color --cache --cache-location .eslintcache",
|
|
121
127
|
"files": [
|
|
122
128
|
"src/**/*.ts",
|
|
129
|
+
"src/**/*.js",
|
|
123
130
|
"test/**/*.ts",
|
|
124
131
|
"**/.eslint*",
|
|
125
132
|
"**/tsconfig.json",
|
|
@@ -152,6 +159,7 @@
|
|
|
152
159
|
"files": [
|
|
153
160
|
"test/**/*.ts",
|
|
154
161
|
"src/**/*.ts",
|
|
162
|
+
"src/**/*.js",
|
|
155
163
|
"**/tsconfig.json",
|
|
156
164
|
"../../tsconfig.json",
|
|
157
165
|
"../../vitest.config.ts"
|
|
@@ -159,5 +167,5 @@
|
|
|
159
167
|
"output": []
|
|
160
168
|
}
|
|
161
169
|
},
|
|
162
|
-
"gitHead": "
|
|
170
|
+
"gitHead": "7a8febc345f771e17a39247082eb47333c75001b"
|
|
163
171
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Before, When } from '@wdio/cucumber-framework';
|
|
2
|
+
|
|
3
|
+
// Captures the page as it is, without waiting: put it after a step that waits for something on the
|
|
4
|
+
// page. The snapshot is written under .utam/snapshots/ and copied to latest.json. See the
|
|
5
|
+
// utam-dom-snapshots skill in @simplysf/simply-utam.
|
|
6
|
+
Before(function (scenario) {
|
|
7
|
+
this.domSnapshotScenario = scenario.pickle.name;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// Imported when the step runs, not with this file, so a project whose @simplysf/simply-utam predates
|
|
11
|
+
// DOM snapshots fails only this step, saying what to do, rather than every scenario.
|
|
12
|
+
async function snapshotApi() {
|
|
13
|
+
const api = await import('@simplysf/simply-utam');
|
|
14
|
+
if (typeof api.captureDomSnapshot !== 'function' || typeof api.writeDomSnapshot !== 'function') {
|
|
15
|
+
throw new Error(
|
|
16
|
+
'The installed @simplysf/simply-utam has no DOM snapshots. Upgrade it in package.json to use this step.',
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
return api;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function capture(world, label) {
|
|
23
|
+
const { captureDomSnapshot, writeDomSnapshot } = await snapshotApi();
|
|
24
|
+
const snapshot = await captureDomSnapshot({ trigger: 'step', scenario: world.domSnapshotScenario, label });
|
|
25
|
+
if (snapshot) console.log(`DOM snapshot written to ${await writeDomSnapshot(snapshot)}`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
When('I capture the DOM snapshot', async function () {
|
|
29
|
+
await capture(this);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
When('I capture the DOM snapshot {string}', async function (label) {
|
|
33
|
+
await capture(this, label);
|
|
34
|
+
});
|