-
Notifications
You must be signed in to change notification settings - Fork 22
/
index.js
23 lines (21 loc) · 854 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const beautify = require('pretty')
const isHtmlString = received => received && typeof received === 'string' && received[0] === '<'
const isVueWrapper = received => (
received &&
typeof received === 'object' &&
typeof received.html === 'function'
)
const removeServerRenderedText = html => html.replace(/ data-server-rendered="true"/, '')
// [-\w]+ will catch 1 or more instances of a-z, A-Z, 0-9, hyphen (-), or underscore (_)
const removeDataTestAttributes = html => html.replace(/ data-test="[-\w]+"/g, '')
module.exports = {
test (received) {
return isHtmlString(received) || isVueWrapper(received)
},
print (received) {
let html = (isVueWrapper(received) ? received.html() : received) || ''
html = removeServerRenderedText(html)
html = removeDataTestAttributes(html)
return beautify(html, { indent_size: 2 })
}
}