mirror of
https://github.com/datashard/snapshot.git
synced 2024-11-22 06:02:29 +00:00
working on stripping react id
This commit is contained in:
parent
7683fe3678
commit
fb79175620
2 changed files with 17 additions and 13 deletions
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"standard.enable": false,
|
||||
"eslint.enable": true,
|
||||
"eslint.autoFixOnSave": true,
|
||||
"eslint.autoFixOnSave": false,
|
||||
"git.ignoreLimitWarning": true
|
||||
}
|
||||
|
|
28
src/utils.js
28
src/utils.js
|
@ -1,6 +1,10 @@
|
|||
/* global Cypress */
|
||||
const sd = require('@wildpeaks/snapshot-dom')
|
||||
|
||||
function isJqueryElement (x) {
|
||||
return 'wrap' in x
|
||||
}
|
||||
|
||||
// converts DOM element to a JSON object
|
||||
function serializeDomElement ($el) {
|
||||
// console.log('snapshot value!', $el)
|
||||
|
@ -17,23 +21,23 @@ function serializeDomElement ($el) {
|
|||
return json
|
||||
}
|
||||
|
||||
const stripAttribute = (attribute) => (el$) => {
|
||||
el$.removeAttr(attribute)
|
||||
el$.children().each(stripAttribute(attribute))
|
||||
return el$
|
||||
const stripReactIdAttributes = html => {
|
||||
const dataReactId = /data\-reactid="[\.\d\$\-abcdfef]+"/g
|
||||
return html.replace(dataReactId, '')
|
||||
}
|
||||
|
||||
const serializeReactToHTML = (el$) => {
|
||||
const copy$ = Cypress.$(el$.outerHTML)
|
||||
const removedReactId = stripAttribute('data-reactid')(copy$)
|
||||
return removedReactId.html()
|
||||
const serializeReactToHTML = el$ => {
|
||||
debugger
|
||||
const html = el$[0].outerHTML
|
||||
const stripped = stripReactIdAttributes(html)
|
||||
return stripped
|
||||
}
|
||||
|
||||
const identity = (x) => x
|
||||
const identity = x => x
|
||||
|
||||
const publicProps = (name) => !name.startsWith('__')
|
||||
const publicProps = name => !name.startsWith('__')
|
||||
|
||||
const countSnapshots = (snapshots) =>
|
||||
const countSnapshots = snapshots =>
|
||||
Object.keys(snapshots).filter(publicProps).length
|
||||
|
||||
module.exports = {
|
||||
|
@ -42,5 +46,5 @@ module.exports = {
|
|||
serializeReactToHTML,
|
||||
identity,
|
||||
countSnapshots,
|
||||
stripAttribute
|
||||
isJqueryElement
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue