mirror of
https://github.com/datashard/snapshot.git
synced 2024-11-21 21:52:28 +00:00
working on HTML serialization
This commit is contained in:
parent
b6416087b1
commit
7683fe3678
3 changed files with 26 additions and 4 deletions
|
@ -3,7 +3,8 @@
|
||||||
"plugin:cypress-dev/general"
|
"plugin:cypress-dev/general"
|
||||||
],
|
],
|
||||||
"rules": {
|
"rules": {
|
||||||
"comma-dangle": ["off"]
|
"comma-dangle": "off",
|
||||||
|
"no-debugger": "warn"
|
||||||
},
|
},
|
||||||
"env": {
|
"env": {
|
||||||
"node": true
|
"node": true
|
||||||
|
|
10
src/index.js
10
src/index.js
|
@ -5,7 +5,12 @@ const itsName = require('its-name')
|
||||||
const { initStore } = require('snap-shot-store')
|
const { initStore } = require('snap-shot-store')
|
||||||
const la = require('lazy-ass')
|
const la = require('lazy-ass')
|
||||||
const is = require('check-more-types')
|
const is = require('check-more-types')
|
||||||
const { serializeDomElement, identity, countSnapshots } = require('./utils')
|
const {
|
||||||
|
serializeDomElement,
|
||||||
|
serializeReactToHTML,
|
||||||
|
identity,
|
||||||
|
countSnapshots
|
||||||
|
} = require('./utils')
|
||||||
const switchcase = require('switchcase')
|
const switchcase = require('switchcase')
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
|
|
||||||
|
@ -104,7 +109,8 @@ function registerCypressSnapshot () {
|
||||||
}
|
}
|
||||||
|
|
||||||
const pickSerializer = switchcase({
|
const pickSerializer = switchcase({
|
||||||
[isJqueryElement]: serializeDomElement,
|
// [isJqueryElement]: serializeDomElement,
|
||||||
|
[isJqueryElement]: serializeReactToHTML,
|
||||||
default: identity
|
default: identity
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
17
src/utils.js
17
src/utils.js
|
@ -1,3 +1,4 @@
|
||||||
|
/* global Cypress */
|
||||||
const sd = require('@wildpeaks/snapshot-dom')
|
const sd = require('@wildpeaks/snapshot-dom')
|
||||||
|
|
||||||
// converts DOM element to a JSON object
|
// converts DOM element to a JSON object
|
||||||
|
@ -16,6 +17,18 @@ function serializeDomElement ($el) {
|
||||||
return json
|
return json
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const stripAttribute = (attribute) => (el$) => {
|
||||||
|
el$.removeAttr(attribute)
|
||||||
|
el$.children().each(stripAttribute(attribute))
|
||||||
|
return el$
|
||||||
|
}
|
||||||
|
|
||||||
|
const serializeReactToHTML = (el$) => {
|
||||||
|
const copy$ = Cypress.$(el$.outerHTML)
|
||||||
|
const removedReactId = stripAttribute('data-reactid')(copy$)
|
||||||
|
return removedReactId.html()
|
||||||
|
}
|
||||||
|
|
||||||
const identity = (x) => x
|
const identity = (x) => x
|
||||||
|
|
||||||
const publicProps = (name) => !name.startsWith('__')
|
const publicProps = (name) => !name.startsWith('__')
|
||||||
|
@ -26,6 +39,8 @@ const countSnapshots = (snapshots) =>
|
||||||
module.exports = {
|
module.exports = {
|
||||||
SNAPSHOT_FILE_NAME: 'snapshots.js',
|
SNAPSHOT_FILE_NAME: 'snapshots.js',
|
||||||
serializeDomElement,
|
serializeDomElement,
|
||||||
|
serializeReactToHTML,
|
||||||
identity,
|
identity,
|
||||||
countSnapshots
|
countSnapshots,
|
||||||
|
stripAttribute
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue