@ctrl/dom 0.1.4 → 0.1.5
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/aria/_chunks/roles-list-BXCvPLJT.cjs +4 -0
- package/dist/aria/_chunks/roles-list-rVVxaIPs.js +4 -0
- package/dist/aria/index.cjs +1 -232
- package/dist/aria/index.js +1 -198
- package/dist/aria/internal.cjs +1 -69
- package/dist/aria/internal.js +1 -30
- package/dist/cli/_chunks/report-z52LF7nA.js +12 -0
- package/dist/cli/_chunks/rolldown-runtime-H3fMLYWS.js +1 -0
- package/dist/cli/ctrl-dom.js +2 -181
- package/dist/cli/jest-reporter.js +2 -54
- package/dist/cli/vitest-reporter.js +2 -81
- package/dist/dom/_chunks/src-sZY6a2LC.js +49 -0
- package/dist/dom/index.js +1 -3
- package/dist/dom/internal.js +1 -434
- package/dist/dom/types/window/clock.d.ts +2 -2
- package/dist/jest-dom/_chunks/matchers-CGTk9GX9.cjs +31 -0
- package/dist/jest-dom/_chunks/matchers-Chf0yHoo.js +31 -0
- package/dist/jest-dom/index.cjs +1 -5
- package/dist/jest-dom/index.js +1 -6
- package/dist/jest-dom/jest-globals.cjs +1 -6
- package/dist/jest-dom/jest-globals.js +1 -7
- package/dist/jest-dom/matchers.cjs +1 -53
- package/dist/jest-dom/matchers.js +1 -3
- package/dist/jest-dom/vitest.cjs +1 -6
- package/dist/jest-dom/vitest.js +1 -7
- package/dist/react/_chunks/pure-CCeTO5Mk.js +1 -0
- package/dist/react/_chunks/pure-DQzwul4s.cjs +1 -0
- package/dist/react/dont-cleanup-after-each.cjs +1 -3
- package/dist/react/dont-cleanup-after-each.js +1 -4
- package/dist/react/index.cjs +1 -47
- package/dist/react/index.js +1 -35
- package/dist/react/pure.cjs +1 -17
- package/dist/react/pure.js +1 -5
- package/dist/register/index.js +1 -11
- package/dist/register/pure.js +1 -147
- package/dist/testing-library/_chunks/aria-snapshot-diff-80G4meO2.cjs +14 -0
- package/dist/testing-library/_chunks/aria-snapshot-diff-B1L8s_sM.js +14 -0
- package/dist/testing-library/agent.cjs +10 -720
- package/dist/testing-library/agent.js +10 -712
- package/dist/testing-library/index.cjs +19 -2459
- package/dist/testing-library/index.js +19 -2380
- package/dist/user-event/index.cjs +33 -3924
- package/dist/user-event/index.js +33 -3899
- package/dist/user-event/types/ctrl-dom.d.ts +1 -1
- package/dist/vitest-environment/_chunks/rolldown-runtime-BhWHdk3m.js +1 -0
- package/dist/vitest-environment/failure-snapshot.js +1 -42
- package/dist/vitest-environment/index.js +1 -185
- package/dist/vitest-environment/plugin.js +1 -90
- package/package.json +1 -1
- package/dist/aria/_chunks/roles-list-CYZF-l9K.js +0 -1503
- package/dist/aria/_chunks/roles-list-D4WCyRO_.cjs +0 -1754
- package/dist/cli/_chunks/report-DdncYfuJ.js +0 -93
- package/dist/dom/_chunks/src-Cp3oLry4.js +0 -47610
- package/dist/jest-dom/_chunks/matchers-CDnnXUfG.js +0 -2211
- package/dist/jest-dom/_chunks/matchers-D988Ducb.cjs +0 -2516
- package/dist/react/_chunks/pure-DZ97z2oT.cjs +0 -498
- package/dist/react/_chunks/pure-PtE2hivW.js +0 -420
- package/dist/testing-library/_chunks/aria-snapshot-diff-D7PzpXew.cjs +0 -1170
- package/dist/testing-library/_chunks/aria-snapshot-diff-Q8Wj33K0.js +0 -985
|
@@ -1,985 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
import { $impl, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, ELEMENT_NODE, HTML_NS, SVG_NS, T, TEXT_NODE, attr, matches, serializeNode, setFailureSnapshot } from "@ctrl/dom/internal";
|
|
3
|
-
import { readFileSync } from "node:fs";
|
|
4
|
-
import { roleSupportsProp } from "@ctrl/dom/aria";
|
|
5
|
-
import { ariaCheckedState, ariaPressedState, computeAccessibleNameImpl, computeAriaBusy, computeAriaCurrent, computeAriaExpanded, computeAriaSelected, computeHeadingLevel, isDisabledImpl, isDisplayInline, isDisplayNone, isInaccessibleImpl, isSubtreeInaccessibleImpl, isVisibilityHidden, tlRole } from "@ctrl/dom/aria/internal";
|
|
6
|
-
|
|
7
|
-
// src/get-user-code-frame.ts
|
|
8
|
-
const OWN_DIR = new URL("./", import.meta.url).pathname;
|
|
9
|
-
let deps;
|
|
10
|
-
function loadDeps() {
|
|
11
|
-
if (deps !== void 0) return deps;
|
|
12
|
-
try {
|
|
13
|
-
const req = createRequire(import.meta.url);
|
|
14
|
-
deps = {
|
|
15
|
-
codeFrameColumns: req("@babel/code-frame").codeFrameColumns,
|
|
16
|
-
picocolors: req("picocolors")
|
|
17
|
-
};
|
|
18
|
-
} catch {
|
|
19
|
-
deps = null;
|
|
20
|
-
}
|
|
21
|
-
return deps;
|
|
22
|
-
}
|
|
23
|
-
function getCodeFrame(frame) {
|
|
24
|
-
const { codeFrameColumns, picocolors } = loadDeps();
|
|
25
|
-
const locationStart = frame.indexOf("(") + 1;
|
|
26
|
-
const locationEnd = frame.indexOf(")");
|
|
27
|
-
const frameLocation = frame.slice(locationStart, locationEnd);
|
|
28
|
-
const frameLocationElements = frameLocation.split(":");
|
|
29
|
-
const [filename, line, column] = [
|
|
30
|
-
frameLocationElements[0],
|
|
31
|
-
parseInt(frameLocationElements[1], 10),
|
|
32
|
-
parseInt(frameLocationElements[2], 10)
|
|
33
|
-
];
|
|
34
|
-
let rawFileContents = "";
|
|
35
|
-
try {
|
|
36
|
-
rawFileContents = readFileSync(filename, "utf-8");
|
|
37
|
-
} catch {
|
|
38
|
-
return "";
|
|
39
|
-
}
|
|
40
|
-
const codeFrame = codeFrameColumns(rawFileContents, { start: {
|
|
41
|
-
line,
|
|
42
|
-
column
|
|
43
|
-
} }, {
|
|
44
|
-
highlightCode: true,
|
|
45
|
-
linesBelow: 0
|
|
46
|
-
});
|
|
47
|
-
return `${picocolors.dim(frameLocation)}\n${codeFrame}\n`;
|
|
48
|
-
}
|
|
49
|
-
function getUserCodeFrame() {
|
|
50
|
-
const d = loadDeps();
|
|
51
|
-
if (!d || !readFileSync || !d.codeFrameColumns) return "";
|
|
52
|
-
return getCodeFrame((/* @__PURE__ */ new Error()).stack.split("\n").slice(1).find((frame) => !frame.includes("node_modules/") && !frame.includes(OWN_DIR)));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// src/helpers.ts
|
|
56
|
-
/**
|
|
57
|
-
* Upstream only detects Jest's fake timers (legacy: `setTimeout._isMockFunction`, modern:
|
|
58
|
-
* `setTimeout.clock`). Divergence (intentional): when there is no `jest` global we also detect
|
|
59
|
-
* @sinonjs/fake-timers clocks, which is what Vitest's `vi.useFakeTimers()` installs (the
|
|
60
|
-
* faked `setTimeout` carries a `clock` with `tick`). Upstream's waitFor hangs under Vitest
|
|
61
|
-
* fake timers; ours advances them like it does for Jest.
|
|
62
|
-
*/
|
|
63
|
-
function jestFakeTimersAreEnabled() {
|
|
64
|
-
if (typeof jest !== "undefined" && jest !== null) return setTimeout._isMockFunction === true || Object.hasOwn(setTimeout, "clock");
|
|
65
|
-
const clock = setTimeout.clock;
|
|
66
|
-
return clock != null && typeof clock.tick === "function";
|
|
67
|
-
}
|
|
68
|
-
/** Advance whichever fake clock `jestFakeTimersAreEnabled` detected by `ms`. */
|
|
69
|
-
function advanceFakeTimersByTime(ms) {
|
|
70
|
-
if (typeof jest !== "undefined" && jest !== null) {
|
|
71
|
-
jest.advanceTimersByTime(ms);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const vi = globalThis.vi;
|
|
75
|
-
if (vi != null && typeof vi.advanceTimersByTime === "function" && typeof vi.isFakeTimers === "function" && vi.isFakeTimers()) {
|
|
76
|
-
vi.advanceTimersByTime(ms);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
setTimeout.clock.tick(ms);
|
|
80
|
-
}
|
|
81
|
-
function getDocument() {
|
|
82
|
-
if (typeof window === "undefined") throw new Error("Could not find default container");
|
|
83
|
-
return window.document;
|
|
84
|
-
}
|
|
85
|
-
function getWindowFromNode(node) {
|
|
86
|
-
if (node.defaultView) return node.defaultView;
|
|
87
|
-
else if (node.ownerDocument && node.ownerDocument.defaultView) return node.ownerDocument.defaultView;
|
|
88
|
-
else if (node.window) return node.window;
|
|
89
|
-
else if (node.ownerDocument && node.ownerDocument.defaultView === null) throw new Error(`It looks like the window object is not available for the provided node.`);
|
|
90
|
-
else if (node.then instanceof Function) throw new Error(`It looks like you passed a Promise object instead of a DOM node. Did you do something like \`fireEvent.click(screen.findBy...\` when you meant to use a \`getBy\` query \`fireEvent.click(screen.getBy...\`, or await the findBy query \`fireEvent.click(await screen.findBy...\`?`);
|
|
91
|
-
else if (Array.isArray(node)) throw new Error(`It looks like you passed an Array instead of a DOM node. Did you do something like \`fireEvent.click(screen.getAllBy...\` when you meant to use a \`getBy\` query \`fireEvent.click(screen.getBy...\`?`);
|
|
92
|
-
else if (typeof node.debug === "function" && typeof node.logTestingPlaygroundURL === "function") throw new Error(`It looks like you passed a \`screen\` object. Did you do something like \`fireEvent.click(screen, ...\` when you meant to use a query, e.g. \`fireEvent.click(screen.getBy..., \`?`);
|
|
93
|
-
else throw new Error(`The given node is not an Element, the node type is: ${typeof node}.`);
|
|
94
|
-
}
|
|
95
|
-
function checkContainerType(container) {
|
|
96
|
-
if (!container || !(typeof container.querySelector === "function") || !(typeof container.querySelectorAll === "function")) throw new TypeError(`Expected container to be an Element, a Document or a DocumentFragment but got ${getTypeName(container)}.`);
|
|
97
|
-
}
|
|
98
|
-
function getTypeName(object) {
|
|
99
|
-
if (typeof object === "object") return object === null ? "null" : object.constructor.name;
|
|
100
|
-
return typeof object;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* The NodeImpl behind a container passed to a query. Queries in this package walk
|
|
104
|
-
* @ctrl/dom internals directly; `checkContainerType` must have run first.
|
|
105
|
-
*/
|
|
106
|
-
function implOf(node) {
|
|
107
|
-
const impl = node[$impl];
|
|
108
|
-
if (impl === void 0) throw new TypeError("@ctrl/dom/testing-library requires nodes created by @ctrl/dom.");
|
|
109
|
-
return impl;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// src/selectors.ts
|
|
113
|
-
function matchesSelector(el, selector) {
|
|
114
|
-
return el.type === ELEMENT_NODE && matches(el, selector);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// src/agent-debug.ts
|
|
118
|
-
/** `CTRL_DOM_DEBUG` when it names an agent format, else null (upstream behavior). */
|
|
119
|
-
function envDebugFormat() {
|
|
120
|
-
const raw = typeof process !== "undefined" ? process.env?.CTRL_DOM_DEBUG : void 0;
|
|
121
|
-
if (raw === void 0 || raw === "") return null;
|
|
122
|
-
const value = String(raw).trim().toLowerCase();
|
|
123
|
-
if (value === "aria") return "aria";
|
|
124
|
-
if (value === "compact" || value === "html") return "compact";
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
/** Line budget for snapshots inside error messages. */
|
|
128
|
-
const ERROR_MAX_LINES = 100;
|
|
129
|
-
function containerLabel(container) {
|
|
130
|
-
const impl = container?.[$impl];
|
|
131
|
-
if (impl === void 0) return "the container";
|
|
132
|
-
if (impl.type === 9) return "the document";
|
|
133
|
-
return describeElement(impl);
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* The text that replaces upstream's `Ignored nodes: comments, script, style\n<prettyDOM>` in a
|
|
137
|
-
* query error under agent mode.
|
|
138
|
-
*/
|
|
139
|
-
function agentErrorContext(container, format, prettyDOM) {
|
|
140
|
-
if (format === "aria") return `Accessibility snapshot of ${containerLabel(container)} (CTRL_DOM_DEBUG=aria):\n${ariaSnapshot(container, { maxLines: envMaxLines() ?? 100 })}`;
|
|
141
|
-
return `DOM of ${containerLabel(container)} without class/style/SVG internals (CTRL_DOM_DEBUG=compact):\n${prettyDOM(container, void 0, { format: "compact" })}`;
|
|
142
|
-
}
|
|
143
|
-
/** One element of a "Found multiple elements" error, under agent mode. */
|
|
144
|
-
function agentElementSummary(element) {
|
|
145
|
-
return ariaSnapshot(element, { maxLines: 12 });
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// src/aria-snapshot.ts
|
|
149
|
-
const DEFAULT_MAX_LINES = 200;
|
|
150
|
-
const DEFAULT_MAX_TEXT = 100;
|
|
151
|
-
const DEFAULT_COLLAPSE_AFTER = 5;
|
|
152
|
-
/** `CTRL_DOM_DEBUG_LINES`, when set to a positive number. */
|
|
153
|
-
function envMaxLines() {
|
|
154
|
-
const raw = typeof process !== "undefined" ? process.env?.CTRL_DOM_DEBUG_LINES : void 0;
|
|
155
|
-
const n = raw ? Number(raw) : NaN;
|
|
156
|
-
return n > 0 ? n : void 0;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* The accessibility tree of `container` (default `document.body`) in Playwright's aria snapshot
|
|
160
|
-
* YAML. A body, document or fragment prints its children; any other element prints itself.
|
|
161
|
-
*/
|
|
162
|
-
function ariaSnapshot(container, options = {}) {
|
|
163
|
-
const { header, lines, empty } = ariaSnapshotLines(container, options);
|
|
164
|
-
if (empty !== null) return header + empty;
|
|
165
|
-
return header + budgetLines(lines, options.maxLines ?? envMaxLines() ?? DEFAULT_MAX_LINES).join("\n");
|
|
166
|
-
}
|
|
167
|
-
setFailureSnapshot((body) => ariaSnapshot(body, { maxLines: 2e3 }));
|
|
168
|
-
function buildTree(container, options) {
|
|
169
|
-
const root = rootImpl(container);
|
|
170
|
-
const ctx = new SnapshotContext(root, options);
|
|
171
|
-
const children = [];
|
|
172
|
-
let header = "";
|
|
173
|
-
if (!ctx.includeHidden && root.type === ELEMENT_NODE && isInaccessibleImpl(root)) {
|
|
174
|
-
header = `# hidden from the accessibility tree: ${hiddenReason(root)}\n`;
|
|
175
|
-
ctx.includeHidden = true;
|
|
176
|
-
ctx.forceHidden = true;
|
|
177
|
-
}
|
|
178
|
-
if (root.type === ELEMENT_NODE && root !== bodyOf(root)) ctx.visitElement(root, children, ctx.forceHidden);
|
|
179
|
-
else ctx.visitChildren(root, children, false, false);
|
|
180
|
-
finishChildren(children, null);
|
|
181
|
-
return {
|
|
182
|
-
root,
|
|
183
|
-
ctx,
|
|
184
|
-
children,
|
|
185
|
-
header
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
/** The tree of `container` as nodes and text runs, before rendering (no budget, no collapsing). */
|
|
189
|
-
function ariaSnapshotTree(container, options = {}) {
|
|
190
|
-
return buildTree(container, options).children;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* The rendered snapshot before the line budget: the `# hidden …` header (or ""), the lines, and
|
|
194
|
-
* the `# no accessible content` text when there are none.
|
|
195
|
-
*/
|
|
196
|
-
function ariaSnapshotLines(container, options = {}) {
|
|
197
|
-
const { root, ctx, children, header } = buildTree(container, options);
|
|
198
|
-
const lines = [];
|
|
199
|
-
ctx.renderList(children, "", lines);
|
|
200
|
-
const empty = lines.length > 0 ? null : ctx.sawHidden ? "# no accessible content (hidden elements exist: pass { hidden: true })" : "# no accessible content";
|
|
201
|
-
if (root === bodyOf(root) && envDebugFormat() !== null) recordBodySnapshot(root.doc, empty ?? lines.join("\n"));
|
|
202
|
-
return {
|
|
203
|
-
header,
|
|
204
|
-
lines,
|
|
205
|
-
empty
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
/** `lines` cut to `maxLines`, ending with a `# … N more lines` comment. */
|
|
209
|
-
function budgetLines(lines, maxLines) {
|
|
210
|
-
if (lines.length <= maxLines) return lines;
|
|
211
|
-
const rest = lines.length - maxLines;
|
|
212
|
-
const out = lines.slice(0, maxLines);
|
|
213
|
-
out.push(`# … ${rest} more line${rest === 1 ? "" : "s"} (raise maxLines or CTRL_DOM_DEBUG_LINES)`);
|
|
214
|
-
return out;
|
|
215
|
-
}
|
|
216
|
-
const LAST_BODY_SNAPSHOT = Symbol.for("ctrl-dom.agent.lastBodySnapshot");
|
|
217
|
-
function recordBodySnapshot(doc, text) {
|
|
218
|
-
if (doc != null) Object.defineProperty(doc, LAST_BODY_SNAPSHOT, {
|
|
219
|
-
value: text,
|
|
220
|
-
configurable: true,
|
|
221
|
-
writable: true,
|
|
222
|
-
enumerable: false
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
/** The last whole-page snapshot taken in agent mode since `resetBodySnapshot`, or undefined. */
|
|
226
|
-
function lastBodySnapshot(doc) {
|
|
227
|
-
return doc?.[LAST_BODY_SNAPSHOT];
|
|
228
|
-
}
|
|
229
|
-
/** Forget the last whole-page snapshot (at the start of each test). */
|
|
230
|
-
function resetBodySnapshot(doc) {
|
|
231
|
-
if (doc != null && Object.hasOwn(doc, LAST_BODY_SNAPSHOT)) delete doc[LAST_BODY_SNAPSHOT];
|
|
232
|
-
}
|
|
233
|
-
function rootImpl(container) {
|
|
234
|
-
const node = container ?? getDocument().body;
|
|
235
|
-
const impl = node?.[$impl];
|
|
236
|
-
if (impl === void 0) throw new TypeError(`Expected an element, document or fragment but got ${node === null ? "null" : typeof node}`);
|
|
237
|
-
if (impl.type === DOCUMENT_NODE || impl.tag === T.html && impl.ns === HTML_NS) {
|
|
238
|
-
const body = impl.doc?.body;
|
|
239
|
-
return body ? body[$impl] : impl;
|
|
240
|
-
}
|
|
241
|
-
return impl;
|
|
242
|
-
}
|
|
243
|
-
function bodyOf(impl) {
|
|
244
|
-
const body = impl.doc?.body;
|
|
245
|
-
return body ? body[$impl] : null;
|
|
246
|
-
}
|
|
247
|
-
/** Collapse whitespace like the accessible name computation does for text. */
|
|
248
|
-
function normalizeSpace(s) {
|
|
249
|
-
return s.replace(/[\t\n\f\r ]+/g, " ");
|
|
250
|
-
}
|
|
251
|
-
function truncate(s, max) {
|
|
252
|
-
return s.length > max ? s.slice(0, Math.max(1, max - 1)) + "…" : s;
|
|
253
|
-
}
|
|
254
|
-
/** A double-quoted YAML/JSON string (Playwright prints names this way). */
|
|
255
|
-
function quote(s) {
|
|
256
|
-
return JSON.stringify(s);
|
|
257
|
-
}
|
|
258
|
-
const NEEDS_QUOTES = /^$|^[\s\-?:,[\]{}#&*!|>'"%@`]|[\s]$|:$|: | #|^(true|false|null|yes|no|on|off|~)$|^[-+]?(\d+\.?\d*|\.\d+)(e[-+]?\d+)?$/i;
|
|
259
|
-
/** A YAML value: plain when unambiguous, double-quoted otherwise. */
|
|
260
|
-
function yamlValue(s) {
|
|
261
|
-
return NEEDS_QUOTES.test(s) ? quote(s) : s;
|
|
262
|
-
}
|
|
263
|
-
/** `- role "name" [props]` without the leading dash. */
|
|
264
|
-
function nodeKey(node, maxText) {
|
|
265
|
-
let key = node.role;
|
|
266
|
-
if (node.name !== "") key += " " + quote(truncate(node.name, maxText));
|
|
267
|
-
for (let i = 0; i < node.props.length; i++) key += " " + node.props[i];
|
|
268
|
-
return key;
|
|
269
|
-
}
|
|
270
|
-
/** Short CSS-ish description of an element for comments: `<div id="x">`, `<span data-testid="y">`. */
|
|
271
|
-
function describeElement(impl) {
|
|
272
|
-
const tag = impl.name;
|
|
273
|
-
if (impl.id !== "") return `<${tag} id="${impl.id}">`;
|
|
274
|
-
const testId = attr(impl, "data-testid");
|
|
275
|
-
if (testId !== null) return `<${tag} data-testid="${testId}">`;
|
|
276
|
-
return `<${tag}>`;
|
|
277
|
-
}
|
|
278
|
-
/** Why `impl` is excluded from the accessibility tree, or "" when it is not. */
|
|
279
|
-
function hiddenReason(impl) {
|
|
280
|
-
const chain = hiddenChainReason(impl);
|
|
281
|
-
if (chain !== "") return chain;
|
|
282
|
-
return isVisibilityHidden(impl) ? `visibility: hidden on ${describeElement(impl)}` : "";
|
|
283
|
-
}
|
|
284
|
-
function hiddenChainReason(impl) {
|
|
285
|
-
for (let cur = impl; cur !== null && cur.type === ELEMENT_NODE; cur = cur.parent) {
|
|
286
|
-
if (cur.ns === HTML_NS && attr(cur, "hidden") !== null) return `hidden attribute on ${describeElement(cur)}`;
|
|
287
|
-
if (attr(cur, "aria-hidden") === "true") return `aria-hidden="true" on ${describeElement(cur)}`;
|
|
288
|
-
if (isDisplayNone(cur)) return `display: none on ${describeElement(cur)}`;
|
|
289
|
-
}
|
|
290
|
-
return "";
|
|
291
|
-
}
|
|
292
|
-
const PRESENTATIONAL = /* @__PURE__ */ new Set([
|
|
293
|
-
"",
|
|
294
|
-
"generic",
|
|
295
|
-
"none",
|
|
296
|
-
"presentation"
|
|
297
|
-
]);
|
|
298
|
-
function isSkippedTag(impl) {
|
|
299
|
-
if (impl.ns !== HTML_NS) return false;
|
|
300
|
-
switch (impl.tag) {
|
|
301
|
-
case T.script:
|
|
302
|
-
case T.style:
|
|
303
|
-
case T.template:
|
|
304
|
-
case T.noscript:
|
|
305
|
-
case T.head: return true;
|
|
306
|
-
}
|
|
307
|
-
return false;
|
|
308
|
-
}
|
|
309
|
-
/** The state/property annotations of one node, in Playwright's order plus ours. */
|
|
310
|
-
function nodeProps(impl, role, active, hidden) {
|
|
311
|
-
const props = [];
|
|
312
|
-
if (roleSupportsProp(role, "aria-checked")) {
|
|
313
|
-
const checked = ariaCheckedState(impl);
|
|
314
|
-
if (checked === true) props.push("[checked]");
|
|
315
|
-
else if (checked === "mixed") props.push("[checked=mixed]");
|
|
316
|
-
}
|
|
317
|
-
if (isDisabledImpl(impl)) props.push("[disabled]");
|
|
318
|
-
const expanded = computeAriaExpanded(impl);
|
|
319
|
-
if (expanded === true) props.push("[expanded]");
|
|
320
|
-
else if (expanded === false) props.push("[expanded=false]");
|
|
321
|
-
if (active) props.push("[active]");
|
|
322
|
-
const level = role === "heading" ? computeHeadingLevel(impl) : levelAttr(impl);
|
|
323
|
-
if (level !== void 0) props.push(`[level=${level}]`);
|
|
324
|
-
const pressed = ariaPressedState(impl);
|
|
325
|
-
if (pressed === true) props.push("[pressed]");
|
|
326
|
-
else if (pressed === "mixed") props.push("[pressed=mixed]");
|
|
327
|
-
else if (pressed === false) props.push("[pressed=false]");
|
|
328
|
-
if (computeAriaSelected(impl) === true) props.push("[selected]");
|
|
329
|
-
const current = computeAriaCurrent(impl);
|
|
330
|
-
if (current === true) props.push("[current]");
|
|
331
|
-
else if (typeof current === "string" && current !== "") props.push(`[current=${current}]`);
|
|
332
|
-
if (computeAriaBusy(impl)) props.push("[busy]");
|
|
333
|
-
if (hidden) props.push("[hidden]");
|
|
334
|
-
return props;
|
|
335
|
-
}
|
|
336
|
-
function levelAttr(impl) {
|
|
337
|
-
const v = attr(impl, "aria-level");
|
|
338
|
-
const n = v === null ? NaN : Number(v);
|
|
339
|
-
return n > 0 ? n : void 0;
|
|
340
|
-
}
|
|
341
|
-
const VALUE_ROLES = /* @__PURE__ */ new Set([
|
|
342
|
-
"textbox",
|
|
343
|
-
"searchbox",
|
|
344
|
-
"combobox",
|
|
345
|
-
"spinbutton",
|
|
346
|
-
"slider",
|
|
347
|
-
"progressbar",
|
|
348
|
-
"meter",
|
|
349
|
-
"scrollbar",
|
|
350
|
-
"separator"
|
|
351
|
-
]);
|
|
352
|
-
/** What Playwright prints after the colon for value-bearing widgets. */
|
|
353
|
-
function nodeValue(impl, role) {
|
|
354
|
-
if (!VALUE_ROLES.has(role)) return null;
|
|
355
|
-
const valueText = attr(impl, "aria-valuetext");
|
|
356
|
-
if (valueText !== null) return valueText;
|
|
357
|
-
const valueNow = attr(impl, "aria-valuenow");
|
|
358
|
-
if (valueNow !== null) return valueNow;
|
|
359
|
-
if (impl.ns !== HTML_NS) return null;
|
|
360
|
-
if (impl.tag === T.input || impl.tag === T.textarea) {
|
|
361
|
-
const v = String(impl.node.value ?? "");
|
|
362
|
-
return v === "" ? null : v;
|
|
363
|
-
}
|
|
364
|
-
return null;
|
|
365
|
-
}
|
|
366
|
-
var SnapshotContext = class {
|
|
367
|
-
includeHidden;
|
|
368
|
-
forceHidden = false;
|
|
369
|
-
sawHidden = false;
|
|
370
|
-
maxText;
|
|
371
|
-
collapseAfter;
|
|
372
|
-
urls;
|
|
373
|
-
active;
|
|
374
|
-
constructor(root, options) {
|
|
375
|
-
this.includeHidden = options.hidden === true;
|
|
376
|
-
this.maxText = options.maxTextLength ?? DEFAULT_MAX_TEXT;
|
|
377
|
-
this.collapseAfter = options.collapseAfter ?? DEFAULT_COLLAPSE_AFTER;
|
|
378
|
-
this.urls = options.urls === true;
|
|
379
|
-
const activeElement = root.doc?.activeElement;
|
|
380
|
-
const active = activeElement ? activeElement[$impl] ?? null : null;
|
|
381
|
-
this.active = active !== null && active === bodyOf(root) ? null : active;
|
|
382
|
-
}
|
|
383
|
-
/** Appends `impl`'s children (nodes and merged text runs) to `out`. */
|
|
384
|
-
visitChildren(impl, out, hidden, textHidden) {
|
|
385
|
-
for (let c = impl.first; c !== null; c = c.next) if (c.type === TEXT_NODE) {
|
|
386
|
-
if (!textHidden) appendText(out, c.data);
|
|
387
|
-
} else if (c.type === ELEMENT_NODE) this.visitElement(c, out, hidden);
|
|
388
|
-
else if (c.type === DOCUMENT_FRAGMENT_NODE) this.visitChildren(c, out, hidden, textHidden);
|
|
389
|
-
}
|
|
390
|
-
visitElement(el, out, inheritedHidden) {
|
|
391
|
-
if (isSkippedTag(el)) return;
|
|
392
|
-
let hidden = inheritedHidden;
|
|
393
|
-
if (!hidden && isSubtreeInaccessibleImpl(el)) {
|
|
394
|
-
this.sawHidden = true;
|
|
395
|
-
if (!this.includeHidden) return;
|
|
396
|
-
hidden = true;
|
|
397
|
-
}
|
|
398
|
-
let selfHidden = hidden;
|
|
399
|
-
if (!hidden && isVisibilityHidden(el)) {
|
|
400
|
-
this.sawHidden = true;
|
|
401
|
-
if (!this.includeHidden) {
|
|
402
|
-
this.visitChildren(el, out, false, true);
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
405
|
-
selfHidden = true;
|
|
406
|
-
}
|
|
407
|
-
const role = tlRole(el);
|
|
408
|
-
if (PRESENTATIONAL.has(role)) {
|
|
409
|
-
const block = !isDisplayInline(el);
|
|
410
|
-
if (block) appendBreak(out);
|
|
411
|
-
this.visitChildren(el, out, hidden, false);
|
|
412
|
-
if (block) appendBreak(out);
|
|
413
|
-
return;
|
|
414
|
-
}
|
|
415
|
-
const node = {
|
|
416
|
-
role,
|
|
417
|
-
name: normalizeSpace(computeAccessibleNameImpl(el, void 0, 5)).trim(),
|
|
418
|
-
props: nodeProps(el, role, el === this.active, selfHidden && this.includeHidden),
|
|
419
|
-
value: nodeValue(el, role),
|
|
420
|
-
url: null,
|
|
421
|
-
children: [],
|
|
422
|
-
element: el
|
|
423
|
-
};
|
|
424
|
-
if (this.urls && role === "link") node.url = attr(el, "href");
|
|
425
|
-
if (!(el.ns === HTML_NS && el.tag === T.textarea)) this.visitChildren(el, node.children, hidden, false);
|
|
426
|
-
finishChildren(node.children, node.name);
|
|
427
|
-
out.push(node);
|
|
428
|
-
}
|
|
429
|
-
renderList(list, indent, lines) {
|
|
430
|
-
for (let i = 0; i < list.length; i++) {
|
|
431
|
-
const item = list[i];
|
|
432
|
-
if (typeof item === "string") {
|
|
433
|
-
lines.push(`${indent}- text: ${yamlValue(truncate(item, this.maxText))}`);
|
|
434
|
-
continue;
|
|
435
|
-
}
|
|
436
|
-
let run = 1;
|
|
437
|
-
while (i + run < list.length && typeof list[i + run] !== "string" && list[i + run].role === item.role) run++;
|
|
438
|
-
if (run > this.collapseAfter + 1) {
|
|
439
|
-
for (let k = 0; k < this.collapseAfter; k++) this.renderNode(list[i + k], indent, lines);
|
|
440
|
-
lines.push(`${indent}- ${item.role} … (+${run - this.collapseAfter} more)`);
|
|
441
|
-
i += run - 1;
|
|
442
|
-
continue;
|
|
443
|
-
}
|
|
444
|
-
this.renderNode(item, indent, lines);
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
renderNode(node, indent, lines) {
|
|
448
|
-
const key = nodeKey(node, this.maxText);
|
|
449
|
-
const children = node.children;
|
|
450
|
-
if (node.url === null && (children.length === 0 || children.length === 1 && typeof children[0] === "string" && node.value === null)) {
|
|
451
|
-
const inline = node.value ?? (children.length === 1 ? children[0] : null);
|
|
452
|
-
lines.push(inline === null ? `${indent}- ${key}` : `${indent}- ${key}: ${yamlValue(truncate(inline, this.maxText))}`);
|
|
453
|
-
return;
|
|
454
|
-
}
|
|
455
|
-
lines.push(node.value === null ? `${indent}- ${key}:` : `${indent}- ${key}: ${yamlValue(truncate(node.value, this.maxText))}`);
|
|
456
|
-
const childIndent = indent + " ";
|
|
457
|
-
if (node.url !== null) lines.push(`${childIndent}- /url: ${yamlValue(node.url)}`);
|
|
458
|
-
this.renderList(children, childIndent, lines);
|
|
459
|
-
}
|
|
460
|
-
};
|
|
461
|
-
const BREAK = "\0";
|
|
462
|
-
function appendText(out, data) {
|
|
463
|
-
if (data === "") return;
|
|
464
|
-
const last = out.length - 1;
|
|
465
|
-
if (last >= 0 && typeof out[last] === "string" && out[last] !== BREAK) out[last] = out[last] + data;
|
|
466
|
-
else out.push(data);
|
|
467
|
-
}
|
|
468
|
-
function appendBreak(out) {
|
|
469
|
-
const last = out.length - 1;
|
|
470
|
-
if (last >= 0 && typeof out[last] === "string" && out[last] !== BREAK) out.push(BREAK);
|
|
471
|
-
}
|
|
472
|
-
/** Trim text runs, drop empty ones and text that repeats the name (`name` null at the top level). */
|
|
473
|
-
function finishChildren(children, name) {
|
|
474
|
-
let w = 0;
|
|
475
|
-
for (let r = 0; r < children.length; r++) {
|
|
476
|
-
let c = children[r];
|
|
477
|
-
if (typeof c === "string") {
|
|
478
|
-
if (c === BREAK) continue;
|
|
479
|
-
c = normalizeSpace(c).trim();
|
|
480
|
-
if (c === "") continue;
|
|
481
|
-
}
|
|
482
|
-
children[w++] = c;
|
|
483
|
-
}
|
|
484
|
-
children.length = w;
|
|
485
|
-
if (children.length > 0 && typeof children[0] === "string" && children[0] === name) children.splice(0, 1);
|
|
486
|
-
w = 0;
|
|
487
|
-
for (let r = 0; r < children.length; r++) {
|
|
488
|
-
const c = children[r];
|
|
489
|
-
if (typeof c === "string" && (labels(children[r - 1], c) || labels(children[r + 1], c))) continue;
|
|
490
|
-
children[w++] = c;
|
|
491
|
-
}
|
|
492
|
-
children.length = w;
|
|
493
|
-
}
|
|
494
|
-
const LABELLED_ROLES = /* @__PURE__ */ new Set([
|
|
495
|
-
"textbox",
|
|
496
|
-
"searchbox",
|
|
497
|
-
"combobox",
|
|
498
|
-
"listbox",
|
|
499
|
-
"checkbox",
|
|
500
|
-
"radio",
|
|
501
|
-
"switch",
|
|
502
|
-
"slider",
|
|
503
|
-
"spinbutton",
|
|
504
|
-
"meter",
|
|
505
|
-
"progressbar"
|
|
506
|
-
]);
|
|
507
|
-
function labels(sibling, text) {
|
|
508
|
-
return sibling !== void 0 && typeof sibling !== "string" && sibling.name === text && LABELLED_ROLES.has(sibling.role);
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
// src/pretty-dom.ts
|
|
512
|
-
let prettyFormatModule = null;
|
|
513
|
-
function loadPrettyFormat() {
|
|
514
|
-
return prettyFormatModule ??= createRequire(import.meta.url)("pretty-format");
|
|
515
|
-
}
|
|
516
|
-
/**
|
|
517
|
-
* Upstream re-exports pretty-format's module namespace as `prettyFormat`. Same keys here, but
|
|
518
|
-
* the module is only loaded when one of them is first read (keeps import time low).
|
|
519
|
-
*/
|
|
520
|
-
const prettyFormat = Object.defineProperties({}, {
|
|
521
|
-
format: {
|
|
522
|
-
enumerable: true,
|
|
523
|
-
get: () => loadPrettyFormat().format
|
|
524
|
-
},
|
|
525
|
-
default: {
|
|
526
|
-
enumerable: true,
|
|
527
|
-
get: () => loadPrettyFormat().default
|
|
528
|
-
},
|
|
529
|
-
plugins: {
|
|
530
|
-
enumerable: true,
|
|
531
|
-
get: () => loadPrettyFormat().plugins
|
|
532
|
-
},
|
|
533
|
-
DEFAULT_OPTIONS: {
|
|
534
|
-
enumerable: true,
|
|
535
|
-
get: () => loadPrettyFormat().DEFAULT_OPTIONS
|
|
536
|
-
}
|
|
537
|
-
});
|
|
538
|
-
const shouldHighlight = () => {
|
|
539
|
-
if (typeof process === "undefined") return false;
|
|
540
|
-
let colors;
|
|
541
|
-
try {
|
|
542
|
-
const colorsJSON = process.env?.COLORS;
|
|
543
|
-
if (colorsJSON) colors = JSON.parse(colorsJSON);
|
|
544
|
-
} catch {}
|
|
545
|
-
if (typeof colors === "boolean") return colors;
|
|
546
|
-
else return process.versions !== void 0 && process.versions.node !== void 0;
|
|
547
|
-
};
|
|
548
|
-
function filterCommentsAndDefaultIgnoreTagsTags(value) {
|
|
549
|
-
return value.nodeType !== COMMENT_NODE && (value.nodeType !== ELEMENT_NODE || !value.matches(getConfig().defaultIgnore));
|
|
550
|
-
}
|
|
551
|
-
const NO_COLOR = {
|
|
552
|
-
open: "",
|
|
553
|
-
close: ""
|
|
554
|
-
};
|
|
555
|
-
const EMPTY_COLORS = {
|
|
556
|
-
comment: NO_COLOR,
|
|
557
|
-
content: NO_COLOR,
|
|
558
|
-
prop: NO_COLOR,
|
|
559
|
-
tag: NO_COLOR,
|
|
560
|
-
value: NO_COLOR
|
|
561
|
-
};
|
|
562
|
-
const HIGHLIGHT_COLORS = {
|
|
563
|
-
comment: {
|
|
564
|
-
open: "\x1B[90m",
|
|
565
|
-
close: "\x1B[39m"
|
|
566
|
-
},
|
|
567
|
-
content: {
|
|
568
|
-
open: "\x1B[0m",
|
|
569
|
-
close: "\x1B[0m"
|
|
570
|
-
},
|
|
571
|
-
prop: {
|
|
572
|
-
open: "\x1B[33m",
|
|
573
|
-
close: "\x1B[39m"
|
|
574
|
-
},
|
|
575
|
-
tag: {
|
|
576
|
-
open: "\x1B[36m",
|
|
577
|
-
close: "\x1B[39m"
|
|
578
|
-
},
|
|
579
|
-
value: {
|
|
580
|
-
open: "\x1B[32m",
|
|
581
|
-
close: "\x1B[39m"
|
|
582
|
-
}
|
|
583
|
-
};
|
|
584
|
-
const KNOWN_OPTIONS = /* @__PURE__ */ new Set([
|
|
585
|
-
"callToJSON",
|
|
586
|
-
"compareKeys",
|
|
587
|
-
"escapeRegex",
|
|
588
|
-
"escapeString",
|
|
589
|
-
"highlight",
|
|
590
|
-
"indent",
|
|
591
|
-
"maxDepth",
|
|
592
|
-
"min",
|
|
593
|
-
"plugins",
|
|
594
|
-
"printBasicPrototype",
|
|
595
|
-
"printFunctionName",
|
|
596
|
-
"theme"
|
|
597
|
-
]);
|
|
598
|
-
/** Thrown when the fast printer meets something only pretty-format itself prints identically. */
|
|
599
|
-
const DELEGATE = Symbol("delegate");
|
|
600
|
-
const ELEMENT_REGEXP = /^((HTML|SVG)\w*)?Element$/;
|
|
601
|
-
const ctorIsElementName = /* @__PURE__ */ new WeakMap();
|
|
602
|
-
function isCustomElement(val) {
|
|
603
|
-
const { tagName } = val;
|
|
604
|
-
return Boolean(typeof tagName === "string" && tagName.includes("-") || typeof val.hasAttribute === "function" && val.hasAttribute("is"));
|
|
605
|
-
}
|
|
606
|
-
/** DOMElementFilter `test()` for a node we are about to print. */
|
|
607
|
-
function pluginHandles(impl) {
|
|
608
|
-
const node = impl.node;
|
|
609
|
-
const ctor = node.constructor;
|
|
610
|
-
const constructorName = ctor?.name;
|
|
611
|
-
switch (impl.type) {
|
|
612
|
-
case ELEMENT_NODE: {
|
|
613
|
-
if (!constructorName && !isCustomElement(node)) return false;
|
|
614
|
-
if (typeof ctor !== "function") return ELEMENT_REGEXP.test(constructorName) || isCustomElement(node);
|
|
615
|
-
let ok = ctorIsElementName.get(ctor);
|
|
616
|
-
if (ok === void 0) ctorIsElementName.set(ctor, ok = ELEMENT_REGEXP.test(constructorName));
|
|
617
|
-
return ok || isCustomElement(node);
|
|
618
|
-
}
|
|
619
|
-
case TEXT_NODE: return constructorName === "Text";
|
|
620
|
-
case COMMENT_NODE: return constructorName === "Comment";
|
|
621
|
-
case DOCUMENT_FRAGMENT_NODE: return constructorName === "DocumentFragment";
|
|
622
|
-
}
|
|
623
|
-
return false;
|
|
624
|
-
}
|
|
625
|
-
function escapeHTML(str) {
|
|
626
|
-
if (str.indexOf("<") === -1 && str.indexOf(">") === -1) return str;
|
|
627
|
-
return str.replace(/</g, "<").replace(/>/g, ">");
|
|
628
|
-
}
|
|
629
|
-
function printString(val, config) {
|
|
630
|
-
if (config.escapeString) return "\"" + val.replace(/"|\\/g, "\\$&") + "\"";
|
|
631
|
-
return "\"" + val + "\"";
|
|
632
|
-
}
|
|
633
|
-
function keepChild(child, config) {
|
|
634
|
-
if (config.filterNode !== null) return Boolean(config.filterNode(child.node));
|
|
635
|
-
if (child.type === COMMENT_NODE) return false;
|
|
636
|
-
if (child.type !== ELEMENT_NODE) return true;
|
|
637
|
-
if (config.scriptStyleIgnore) return child.name !== "script" && child.name !== "style";
|
|
638
|
-
return !matchesSelector(child, config.defaultIgnore);
|
|
639
|
-
}
|
|
640
|
-
function tagNameLower(impl) {
|
|
641
|
-
return impl.node.tagName.toLowerCase();
|
|
642
|
-
}
|
|
643
|
-
function printProps(impl, config, indentation) {
|
|
644
|
-
const attrs = impl.attrs;
|
|
645
|
-
if (attrs === null || attrs.length === 0) return "";
|
|
646
|
-
const keys = [];
|
|
647
|
-
const props = /* @__PURE__ */ new Map();
|
|
648
|
-
for (let i = 0; i < attrs.length; i++) {
|
|
649
|
-
if (config.compact && isNoiseAttribute(impl, attrs[i].name)) continue;
|
|
650
|
-
keys.push(attrs[i].name);
|
|
651
|
-
props.set(attrs[i].name, attrs[i].value);
|
|
652
|
-
}
|
|
653
|
-
keys.sort();
|
|
654
|
-
const colors = config.colors;
|
|
655
|
-
let out = "";
|
|
656
|
-
for (let i = 0; i < keys.length; i++) {
|
|
657
|
-
const key = keys[i];
|
|
658
|
-
out += config.spacingInner + indentation + colors.prop.open + key + colors.prop.close + "=" + colors.value.open + printString(props.get(key), config) + colors.value.close;
|
|
659
|
-
}
|
|
660
|
-
return out;
|
|
661
|
-
}
|
|
662
|
-
function isNoiseAttribute(impl, name) {
|
|
663
|
-
if (name === "class" || name === "style") return true;
|
|
664
|
-
return impl.ns === SVG_NS && name !== "role" && name !== "id" && !name.startsWith("aria-") && !name.startsWith("data-");
|
|
665
|
-
}
|
|
666
|
-
const COMPACT_MAX_TEXT = 200;
|
|
667
|
-
function printChildren(impl, config, indentation, depth) {
|
|
668
|
-
if (config.compact && impl.ns === SVG_NS && impl.name === "svg") return "";
|
|
669
|
-
let out = "";
|
|
670
|
-
for (let c = impl.first; c !== null; c = c.next) {
|
|
671
|
-
if (!keepChild(c, config)) continue;
|
|
672
|
-
if (config.compact && c.type === TEXT_NODE && c.data.trim() === "") continue;
|
|
673
|
-
out += config.spacingOuter + indentation + printNode(c, config, indentation, depth);
|
|
674
|
-
}
|
|
675
|
-
return out;
|
|
676
|
-
}
|
|
677
|
-
function printNode(impl, config, indentation, depth) {
|
|
678
|
-
if (!pluginHandles(impl)) throw DELEGATE;
|
|
679
|
-
if (impl.type === TEXT_NODE) {
|
|
680
|
-
const data = config.compact && impl.data.length > COMPACT_MAX_TEXT ? impl.data.slice(0, 199) + "…" : impl.data;
|
|
681
|
-
return config.colors.content.open + escapeHTML(data) + config.colors.content.close;
|
|
682
|
-
}
|
|
683
|
-
if (impl.type === COMMENT_NODE) {
|
|
684
|
-
const commentColor = config.colors.comment;
|
|
685
|
-
return commentColor.open + "<!--" + escapeHTML(impl.data) + "-->" + commentColor.close;
|
|
686
|
-
}
|
|
687
|
-
const type = impl.type === DOCUMENT_FRAGMENT_NODE ? "DocumentFragment" : tagNameLower(impl);
|
|
688
|
-
const tagColor = config.colors.tag;
|
|
689
|
-
if (++depth > config.maxDepth) return tagColor.open + "<" + type + tagColor.close + " …" + tagColor.open + " />" + tagColor.close;
|
|
690
|
-
const childIndentation = indentation + config.indent;
|
|
691
|
-
const printedProps = impl.type === DOCUMENT_FRAGMENT_NODE ? "" : printProps(impl, config, childIndentation);
|
|
692
|
-
const printedChildren = printChildren(impl, config, childIndentation, depth);
|
|
693
|
-
return tagColor.open + "<" + type + (printedProps && tagColor.close + printedProps + config.spacingOuter + indentation + tagColor.open) + (printedChildren ? ">" + tagColor.close + printedChildren + config.spacingOuter + indentation + tagColor.open + "</" + type : (printedProps && !config.min ? "" : " ") + "/") + ">" + tagColor.close;
|
|
694
|
-
}
|
|
695
|
-
/** pretty-format's option validation + config construction for the fast path; null = delegate. */
|
|
696
|
-
function makePrintConfig(options, filterNode) {
|
|
697
|
-
for (const key of Object.keys(options)) if (!KNOWN_OPTIONS.has(key)) return null;
|
|
698
|
-
if (options.plugins !== void 0 || options.theme !== void 0) return null;
|
|
699
|
-
if (options.min && options.indent !== void 0 && options.indent !== 0) return null;
|
|
700
|
-
const min = Boolean(options.min);
|
|
701
|
-
const indentWidth = options.indent !== void 0 ? options.indent : 2;
|
|
702
|
-
const defaultIgnore = getConfig().defaultIgnore;
|
|
703
|
-
return {
|
|
704
|
-
colors: options.highlight ? HIGHLIGHT_COLORS : EMPTY_COLORS,
|
|
705
|
-
escapeString: options.escapeString !== void 0 ? options.escapeString : true,
|
|
706
|
-
indent: min ? "" : new Array(indentWidth + 1).join(" "),
|
|
707
|
-
maxDepth: options.maxDepth !== void 0 ? options.maxDepth : Infinity,
|
|
708
|
-
min,
|
|
709
|
-
spacingInner: min ? " " : "\n",
|
|
710
|
-
spacingOuter: min ? "" : "\n",
|
|
711
|
-
filterNode,
|
|
712
|
-
scriptStyleIgnore: defaultIgnore === "script, style",
|
|
713
|
-
defaultIgnore,
|
|
714
|
-
compact: false
|
|
715
|
-
};
|
|
716
|
-
}
|
|
717
|
-
function formatDOM(dom, filterNode, prettyFormatOptions, compact = false) {
|
|
718
|
-
const allOptions = {
|
|
719
|
-
printFunctionName: false,
|
|
720
|
-
highlight: shouldHighlight(),
|
|
721
|
-
...prettyFormatOptions
|
|
722
|
-
};
|
|
723
|
-
const impl = dom[$impl];
|
|
724
|
-
const effectiveFilter = filterNode ?? filterCommentsAndDefaultIgnoreTagsTags;
|
|
725
|
-
if (impl !== void 0) {
|
|
726
|
-
const config = makePrintConfig(allOptions, filterNode === void 0 ? null : filterNode);
|
|
727
|
-
if (config !== null) {
|
|
728
|
-
config.compact = compact;
|
|
729
|
-
try {
|
|
730
|
-
return printNode(impl, config, "", 0);
|
|
731
|
-
} catch (e) {
|
|
732
|
-
if (e !== DELEGATE) throw e;
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
return formatWithPrettyFormat(dom, effectiveFilter, allOptions);
|
|
737
|
-
}
|
|
738
|
-
/** Upstream's exact formatting call (also the oracle for the fast printer's tests). */
|
|
739
|
-
function formatWithPrettyFormat(dom, filterNode, options) {
|
|
740
|
-
const pf = loadPrettyFormat();
|
|
741
|
-
return pf.format(dom, {
|
|
742
|
-
plugins: [createDOMElementFilter(filterNode), pf.plugins.DOMCollection],
|
|
743
|
-
...options
|
|
744
|
-
});
|
|
745
|
-
}
|
|
746
|
-
function prettyDOM(dom, maxLength, options = {}) {
|
|
747
|
-
if (!dom) dom = getDocument().body;
|
|
748
|
-
const explicitMaxLength = typeof maxLength === "number" ? maxLength : void 0;
|
|
749
|
-
if (typeof maxLength !== "number") maxLength = typeof process !== "undefined" && typeof process.env !== "undefined" && process.env.DEBUG_PRINT_LIMIT || 7e3;
|
|
750
|
-
if (maxLength === 0) return "";
|
|
751
|
-
if (dom.documentElement) dom = dom.documentElement;
|
|
752
|
-
let domTypeName = typeof dom;
|
|
753
|
-
if (domTypeName === "object") domTypeName = dom.constructor.name;
|
|
754
|
-
else dom = {};
|
|
755
|
-
if (!("outerHTML" in dom)) throw new TypeError(`Expected an element or document but got ${domTypeName}`);
|
|
756
|
-
const format = options.format ?? envDebugFormat();
|
|
757
|
-
if (format !== null || "format" in options) {
|
|
758
|
-
const { format: _format, hidden, maxLines, maxTextLength, collapseAfter, urls, ...rest } = options;
|
|
759
|
-
if (format === "aria") {
|
|
760
|
-
const snapshot = ariaSnapshot(dom, {
|
|
761
|
-
hidden,
|
|
762
|
-
maxLines,
|
|
763
|
-
maxTextLength,
|
|
764
|
-
collapseAfter,
|
|
765
|
-
urls
|
|
766
|
-
});
|
|
767
|
-
return explicitMaxLength !== void 0 && snapshot.length > explicitMaxLength ? `${snapshot.slice(0, explicitMaxLength)}...` : snapshot;
|
|
768
|
-
}
|
|
769
|
-
options = rest;
|
|
770
|
-
if (format === "compact") {
|
|
771
|
-
const { filterNode, ...prettyFormatOptions } = {
|
|
772
|
-
highlight: false,
|
|
773
|
-
...options
|
|
774
|
-
};
|
|
775
|
-
const debugContent = formatDOM(dom, filterNode, prettyFormatOptions, true);
|
|
776
|
-
return debugContent.length > maxLength ? `${debugContent.slice(0, maxLength)}...` : debugContent;
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
const { filterNode, ...prettyFormatOptions } = options;
|
|
780
|
-
const debugContent = formatDOM(dom, filterNode, prettyFormatOptions);
|
|
781
|
-
return maxLength !== void 0 && outerHTMLLength(dom) > maxLength ? `${debugContent.slice(0, maxLength)}...` : debugContent;
|
|
782
|
-
}
|
|
783
|
-
function outerHTMLLength(dom) {
|
|
784
|
-
const impl = dom[$impl];
|
|
785
|
-
if (impl !== void 0 && impl.type === ELEMENT_NODE) return serializeNode(impl).length;
|
|
786
|
-
return dom.outerHTML.length;
|
|
787
|
-
}
|
|
788
|
-
const logDOM = (...args) => {
|
|
789
|
-
const userCodeFrame = getUserCodeFrame();
|
|
790
|
-
if (userCodeFrame) console.log(`${prettyDOM(...args)}\n\n${userCodeFrame}`);
|
|
791
|
-
else console.log(prettyDOM(...args));
|
|
792
|
-
};
|
|
793
|
-
function createDOMElementFilter(filterNode) {
|
|
794
|
-
const printPropsPF = (keys, props, config, indentation, depth, refs, printer) => {
|
|
795
|
-
const indentationNext = indentation + config.indent;
|
|
796
|
-
const colors = config.colors;
|
|
797
|
-
return keys.map((key) => {
|
|
798
|
-
const value = props[key];
|
|
799
|
-
let printed = printer(value, config, indentationNext, depth, refs);
|
|
800
|
-
if (typeof value !== "string") {
|
|
801
|
-
if (printed.indexOf("\n") !== -1) printed = config.spacingOuter + indentationNext + printed + config.spacingOuter + indentation;
|
|
802
|
-
printed = "{" + printed + "}";
|
|
803
|
-
}
|
|
804
|
-
return config.spacingInner + indentation + colors.prop.open + key + colors.prop.close + "=" + colors.value.open + printed + colors.value.close;
|
|
805
|
-
}).join("");
|
|
806
|
-
};
|
|
807
|
-
const printText = (text, config) => config.colors.content.open + escapeHTML(text) + config.colors.content.close;
|
|
808
|
-
const printChildrenPF = (children, config, indentation, depth, refs, printer) => children.map((child) => {
|
|
809
|
-
const printedChild = typeof child === "string" ? printText(child, config) : printer(child, config, indentation, depth, refs);
|
|
810
|
-
if (printedChild === "" && typeof child === "object" && child !== null && child.nodeType !== TEXT_NODE) return "";
|
|
811
|
-
return config.spacingOuter + indentation + printedChild;
|
|
812
|
-
}).join("");
|
|
813
|
-
const printElement = (type, printedProps, printedChildren, config, indentation) => {
|
|
814
|
-
const tagColor = config.colors.tag;
|
|
815
|
-
return tagColor.open + "<" + type + (printedProps && tagColor.close + printedProps + config.spacingOuter + indentation + tagColor.open) + (printedChildren ? ">" + tagColor.close + printedChildren + config.spacingOuter + indentation + tagColor.open + "</" + type : (printedProps && !config.min ? "" : " ") + "/") + ">" + tagColor.close;
|
|
816
|
-
};
|
|
817
|
-
const testNode = (val) => {
|
|
818
|
-
const constructorName = val.constructor.name;
|
|
819
|
-
const { nodeType } = val;
|
|
820
|
-
return nodeType === ELEMENT_NODE && (ELEMENT_REGEXP.test(constructorName) || isCustomElement(val)) || nodeType === TEXT_NODE && constructorName === "Text" || nodeType === COMMENT_NODE && constructorName === "Comment" || nodeType === DOCUMENT_FRAGMENT_NODE && constructorName === "DocumentFragment";
|
|
821
|
-
};
|
|
822
|
-
return {
|
|
823
|
-
test: (val) => (val?.constructor?.name || isCustomElement(val)) && testNode(val),
|
|
824
|
-
serialize: (node, config, indentation, depth, refs, printer) => {
|
|
825
|
-
if (node.nodeType === TEXT_NODE) return printText(node.data, config);
|
|
826
|
-
if (node.nodeType === COMMENT_NODE) {
|
|
827
|
-
const commentColor = config.colors.comment;
|
|
828
|
-
return commentColor.open + "<!--" + escapeHTML(node.data) + "-->" + commentColor.close;
|
|
829
|
-
}
|
|
830
|
-
const isFragment = node.nodeType === DOCUMENT_FRAGMENT_NODE;
|
|
831
|
-
const type = isFragment ? `DocumentFragment` : node.tagName.toLowerCase();
|
|
832
|
-
if (++depth > config.maxDepth) {
|
|
833
|
-
const tagColor = config.colors.tag;
|
|
834
|
-
return tagColor.open + "<" + type + tagColor.close + " …" + tagColor.open + " />" + tagColor.close;
|
|
835
|
-
}
|
|
836
|
-
return printElement(type, printPropsPF(isFragment ? [] : Array.from(node.attributes).map((attr) => attr.name).sort(), isFragment ? {} : Array.from(node.attributes).reduce((props, attribute) => {
|
|
837
|
-
props[attribute.name] = attribute.value;
|
|
838
|
-
return props;
|
|
839
|
-
}, {}), config, indentation + config.indent, depth, refs, printer), printChildrenPF(Array.prototype.slice.call(node.childNodes || node.children).filter(filterNode), config, indentation + config.indent, depth, refs, printer), config, indentation);
|
|
840
|
-
}
|
|
841
|
-
};
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
// src/config.ts
|
|
845
|
-
let config = {
|
|
846
|
-
testIdAttribute: "data-testid",
|
|
847
|
-
asyncUtilTimeout: 1e3,
|
|
848
|
-
asyncWrapper: (cb) => cb(),
|
|
849
|
-
unstable_advanceTimersWrapper: (cb) => cb(),
|
|
850
|
-
eventWrapper: (cb) => cb(),
|
|
851
|
-
defaultHidden: false,
|
|
852
|
-
defaultIgnore: "script, style",
|
|
853
|
-
showOriginalStackTrace: false,
|
|
854
|
-
throwSuggestions: false,
|
|
855
|
-
getElementError(message, container) {
|
|
856
|
-
const agentFormat = envDebugFormat();
|
|
857
|
-
if (agentFormat !== null) {
|
|
858
|
-
const error = new Error([message, agentErrorContext(container, agentFormat, prettyDOM)].filter(Boolean).join("\n\n"));
|
|
859
|
-
error.name = "TestingLibraryElementError";
|
|
860
|
-
return error;
|
|
861
|
-
}
|
|
862
|
-
const prettifiedDOM = prettyDOM(container);
|
|
863
|
-
const error = new Error([message, `Ignored nodes: comments, ${config.defaultIgnore}\n${prettifiedDOM}`].filter(Boolean).join("\n\n"));
|
|
864
|
-
error.name = "TestingLibraryElementError";
|
|
865
|
-
return error;
|
|
866
|
-
},
|
|
867
|
-
_disableExpensiveErrorDiagnostics: false,
|
|
868
|
-
computedStyleSupportsPseudoElements: false
|
|
869
|
-
};
|
|
870
|
-
function runWithExpensiveErrorDiagnosticsDisabled(callback) {
|
|
871
|
-
try {
|
|
872
|
-
config._disableExpensiveErrorDiagnostics = true;
|
|
873
|
-
return callback();
|
|
874
|
-
} finally {
|
|
875
|
-
config._disableExpensiveErrorDiagnostics = false;
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
function configure(newConfig) {
|
|
879
|
-
if (typeof newConfig === "function") newConfig = newConfig(config);
|
|
880
|
-
config = {
|
|
881
|
-
...config,
|
|
882
|
-
...newConfig
|
|
883
|
-
};
|
|
884
|
-
}
|
|
885
|
-
function getConfig() {
|
|
886
|
-
return config;
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
// src/aria-snapshot-diff.ts
|
|
890
|
-
/** Lines removed (`- `), added (`+ `) and their unchanged parents (` `); "(no changes)" if equal. */
|
|
891
|
-
function diffAriaSnapshots(before, after) {
|
|
892
|
-
const ops = diffLines(before.split("\n"), after.split("\n"));
|
|
893
|
-
const show = new Uint8Array(ops.length);
|
|
894
|
-
let changed = false;
|
|
895
|
-
for (let i = 0; i < ops.length; i++) {
|
|
896
|
-
if (ops[i].kind === "=") continue;
|
|
897
|
-
changed = true;
|
|
898
|
-
show[i] = 1;
|
|
899
|
-
let target = indentOf(ops[i].text);
|
|
900
|
-
for (let j = i - 1; j >= 0 && target > 0; j--) {
|
|
901
|
-
if (ops[j].kind !== "=") continue;
|
|
902
|
-
const indent = indentOf(ops[j].text);
|
|
903
|
-
if (indent < target) {
|
|
904
|
-
show[j] = 1;
|
|
905
|
-
target = indent;
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
if (!changed) return "(no changes)";
|
|
910
|
-
const out = [];
|
|
911
|
-
let last = -1;
|
|
912
|
-
for (let i = 0; i < ops.length; i++) {
|
|
913
|
-
if (show[i] === 0) continue;
|
|
914
|
-
if (last !== -1 && i !== last + 1) out.push(" …");
|
|
915
|
-
out.push(`${ops[i].kind === "=" ? " " : ops[i].kind} ${ops[i].text}`);
|
|
916
|
-
last = i;
|
|
917
|
-
}
|
|
918
|
-
return out.join("\n");
|
|
919
|
-
}
|
|
920
|
-
function indentOf(line) {
|
|
921
|
-
let i = 0;
|
|
922
|
-
while (i < line.length && line.charCodeAt(i) === 32) i++;
|
|
923
|
-
return i;
|
|
924
|
-
}
|
|
925
|
-
/** LCS line diff; the common prefix and suffix are trimmed first, so typical edits stay small. */
|
|
926
|
-
function diffLines(a, b) {
|
|
927
|
-
let start = 0;
|
|
928
|
-
while (start < a.length && start < b.length && a[start] === b[start]) start++;
|
|
929
|
-
let endA = a.length;
|
|
930
|
-
let endB = b.length;
|
|
931
|
-
while (endA > start && endB > start && a[endA - 1] === b[endB - 1]) {
|
|
932
|
-
endA--;
|
|
933
|
-
endB--;
|
|
934
|
-
}
|
|
935
|
-
const ops = [];
|
|
936
|
-
for (let i = 0; i < start; i++) ops.push({
|
|
937
|
-
kind: "=",
|
|
938
|
-
text: a[i]
|
|
939
|
-
});
|
|
940
|
-
const n = endA - start;
|
|
941
|
-
const m = endB - start;
|
|
942
|
-
if (n * m > 4e6) {
|
|
943
|
-
for (let i = start; i < endA; i++) ops.push({
|
|
944
|
-
kind: "-",
|
|
945
|
-
text: a[i]
|
|
946
|
-
});
|
|
947
|
-
for (let j = start; j < endB; j++) ops.push({
|
|
948
|
-
kind: "+",
|
|
949
|
-
text: b[j]
|
|
950
|
-
});
|
|
951
|
-
} else {
|
|
952
|
-
const width = m + 1;
|
|
953
|
-
const lcs = new Uint32Array((n + 1) * width);
|
|
954
|
-
for (let i = n - 1; i >= 0; i--) for (let j = m - 1; j >= 0; j--) lcs[i * width + j] = a[start + i] === b[start + j] ? lcs[(i + 1) * width + j + 1] + 1 : Math.max(lcs[(i + 1) * width + j], lcs[i * width + j + 1]);
|
|
955
|
-
let i = 0;
|
|
956
|
-
let j = 0;
|
|
957
|
-
while (i < n || j < m) if (i < n && j < m && a[start + i] === b[start + j]) {
|
|
958
|
-
ops.push({
|
|
959
|
-
kind: "=",
|
|
960
|
-
text: a[start + i]
|
|
961
|
-
});
|
|
962
|
-
i++;
|
|
963
|
-
j++;
|
|
964
|
-
} else if (i < n && (j === m || lcs[(i + 1) * width + j] >= lcs[i * width + j + 1])) {
|
|
965
|
-
ops.push({
|
|
966
|
-
kind: "-",
|
|
967
|
-
text: a[start + i]
|
|
968
|
-
});
|
|
969
|
-
i++;
|
|
970
|
-
} else {
|
|
971
|
-
ops.push({
|
|
972
|
-
kind: "+",
|
|
973
|
-
text: b[start + j]
|
|
974
|
-
});
|
|
975
|
-
j++;
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
for (let i = endA; i < a.length; i++) ops.push({
|
|
979
|
-
kind: "=",
|
|
980
|
-
text: a[i]
|
|
981
|
-
});
|
|
982
|
-
return ops;
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
export { implOf as A, agentElementSummary as C, checkContainerType as D, advanceFakeTimersByTime as E, getDocument as O, yamlValue as S, matchesSelector as T, nodeKey as _, runWithExpensiveErrorDiagnosticsDisabled as a, resetBodySnapshot as b, prettyFormat as c, ariaSnapshotTree as d, budgetLines as f, lastBodySnapshot as g, hiddenReason as h, getConfig as i, jestFakeTimersAreEnabled as j, getWindowFromNode as k, ariaSnapshot as l, envMaxLines as m, diffLines as n, logDOM as o, describeElement as p, configure as r, prettyDOM as s, diffAriaSnapshots as t, ariaSnapshotLines as u, nodeProps as v, envDebugFormat as w, truncate as x, quote as y };
|