happo-cypress
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -116,3 +116,3 @@ /******/ (function(modules) { // webpackBootstrap | ||
/******/ // eslint-disable-next-line no-unused-vars | ||
/******/ var hotCurrentHash = "fffc3a5f630a31e3e4cc"; | ||
/******/ var hotCurrentHash = "037806a7ee2d6669476a"; | ||
/******/ var hotRequestTimeout = 10000; | ||
@@ -119,0 +119,0 @@ /******/ var hotCurrentModuleData = {}; |
51
index.js
@@ -49,4 +49,4 @@ const crypto = require('crypto'); | ||
const allUrls = []; | ||
const allElements = [subject[0]].concat( | ||
Array.from(subject[0].querySelectorAll('*')), | ||
const allElements = [subject].concat( | ||
Array.from(subject.querySelectorAll('*')), | ||
); | ||
@@ -71,10 +71,52 @@ allElements.forEach(element => { | ||
function inlineCanvases(doc, subject) { | ||
const canvases = []; | ||
if (subject.tagName === 'CANVAS') { | ||
canvases.push(subject); | ||
} | ||
canvases.push(...Array.from(subject.querySelectorAll('canvas'))); | ||
let newSubject = subject; | ||
const replacements = []; | ||
for (const canvas of canvases) { | ||
const image = doc.createElement('img'); | ||
try { | ||
const canvasImageBase64 = canvas.toDataURL('image/png'); | ||
image.src = canvasImageBase64; | ||
const style = window.getComputedStyle(canvas, ''); | ||
image.style.cssText = style.cssText; | ||
canvas.replaceWith(image); | ||
if (canvas === subject) { | ||
// We're inlining the subject (the `cy.get('canvas')` element). Make sure | ||
// we return the modified subject. | ||
newSubject = image; | ||
} | ||
replacements.push({ from: canvas, to: image }); | ||
} catch (e) { | ||
if (e.name === 'SecurityError') { | ||
console.warn('[HAPPO] Failed to convert tainted canvas to PNG image'); | ||
console.warn(e); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} | ||
function cleanup() { | ||
for (const { from, to } of replacements) { | ||
to.replaceWith(from); | ||
} | ||
} | ||
return { subject: newSubject, cleanup }; | ||
} | ||
Cypress.Commands.add( | ||
'happoScreenshot', | ||
{ prevSubject: true }, | ||
(subject, options = {}) => { | ||
(originalSubject, options = {}) => { | ||
const component = options.component || cy.state('runnable').fullTitle(); | ||
const variant = options.variant || 'default'; | ||
cy.document().then(doc => { | ||
const html = subject.prop('outerHTML'); | ||
const { subject, cleanup } = inlineCanvases(doc, originalSubject[0]); | ||
const html = subject.outerHTML; | ||
const assetUrls = getSubjectAssetUrls(subject, doc); | ||
@@ -90,4 +132,5 @@ const cssBlocks = extractCSSBlocks({ doc }); | ||
}); | ||
cleanup(); | ||
}); | ||
}, | ||
); |
{ | ||
"name": "happo-cypress", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "A Happo integration with Cypress.io", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8814606
195
58094