Adjustment to the request debug view functionality
This commit is contained in:
25
tests/support/debug-dom.cjs
Normal file
25
tests/support/debug-dom.cjs
Normal file
@@ -0,0 +1,25 @@
|
||||
function createDebugDom() {
|
||||
const descendants = node => [node, ...node.children.flatMap(descendants)];
|
||||
const document = { activeElement: null };
|
||||
function element(tag) {
|
||||
return {
|
||||
tag, children: [], attributes: {}, listeners: {}, scrollTop: 0, hidden: false, text: "",
|
||||
set textContent(value) { this.text = value; this.children = []; },
|
||||
get textContent() { return this.text; },
|
||||
append(...nodes) { this.children.push(...nodes); },
|
||||
setAttribute(key, value) { this.attributes[key] = value; },
|
||||
getAttribute(key) { return this.attributes[key]; },
|
||||
addEventListener(name, listener) { this.listeners[name] = listener; },
|
||||
focus() { document.activeElement = this; },
|
||||
querySelectorAll(selector) {
|
||||
return descendants(this).filter(node => node.tag === "details"
|
||||
&& node.getAttribute("data-request-id") && (!selector.includes("[open]") || node.open));
|
||||
}
|
||||
};
|
||||
}
|
||||
const panel = element("aside");
|
||||
Object.assign(document, { getElementById: () => panel, createElement: element, createElementNS: (_, tag) => element(tag) });
|
||||
return { document, panel, descendants };
|
||||
}
|
||||
|
||||
module.exports = { createDebugDom };
|
||||
Reference in New Issue
Block a user