diff --git a/tests/hs-run-filtered.js b/tests/hs-run-filtered.js index 8e122561..4b44be5d 100755 --- a/tests/hs-run-filtered.js +++ b/tests/hs-run-filtered.js @@ -99,6 +99,31 @@ class El { if (!('_origDefault' in this)) { this.defaultValue = this.textContent; this._origDefault = true; } } } + get outerHTML() { + const tag = this.tagName.toLowerCase(); + // Merge .id / .className (set directly) into attribute output. + const attrOrder = []; + const attrMap = {}; + if (this.id) { attrMap['id'] = this.id; attrOrder.push('id'); } + if (this.className) { attrMap['class'] = this.className; attrOrder.push('class'); } + for (const k of Object.keys(this.attributes)) { + if (!(k in attrMap)) { attrMap[k] = this.attributes[k]; attrOrder.push(k); } + else attrMap[k] = this.attributes[k]; // prefer explicit attr value when set + } + const attrs = attrOrder.map(k => ` ${k}="${String(attrMap[k]).replace(/"/g, '"')}"`).join(''); + if (VOID_TAGS.has(tag)) return `<${tag}${attrs}>`; + let inner = ''; + if (this.children && this.children.length) { + inner = this.children.map(c => c.outerHTML || c.textContent || '').join(''); + } else if (this.innerHTML) { + inner = this.innerHTML; + } else if (this.innerText !== undefined && this.innerText !== '') { + inner = this.innerText; + } else if (this.textContent) { + inner = this.textContent; + } + return `<${tag}${attrs}>${inner}`; + } get firstElementChild() { return this.children[0]||null; } get lastElementChild() { return this.children[this.children.length-1]||null; } get nextElementSibling() { if(!this.parentElement)return null; const i=this.parentElement.children.indexOf(this); return this.parentElement.children[i+1]||null; }