-
Notifications
You must be signed in to change notification settings - Fork 18
/
debug.js
30 lines (26 loc) · 903 Bytes
/
debug.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// copied from
// https://github.com/kentcdodds/dom-testing-library/blob/2397f644667bc6e65b9becfa8c1615eb285c7673/src/pretty-dom.js
const prettyFormat = require("pretty-format");
const { DOMElement, DOMCollection } = prettyFormat.plugins;
function prettyDOM(htmlElement, maxLength, options) {
if (htmlElement.documentElement) {
// eslint-disable-next-line no-param-reassign
htmlElement = htmlElement.documentElement;
}
const debugContent = prettyFormat(
htmlElement,
Object.assign(
{
plugins: [DOMElement, DOMCollection],
printFunctionName: false,
highlight: true
},
options
)
);
return maxLength !== undefined && htmlElement.outerHTML.length > maxLength
? `${debugContent.slice(0, maxLength)}...`
: debugContent;
}
// eslint-disable-next-line no-console
module.exports = (el = document) => console.log(prettyDOM(el));