Skip to content

Commit

Permalink
Tools: moved prettifying of candidate & reference svgs
Browse files Browse the repository at this point in the history
  • Loading branch information
goransle authored and TorsteinHonsi committed Nov 18, 2020
1 parent c741ea9 commit c6c2574
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
21 changes: 1 addition & 20 deletions test/karma-imagecapture-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,6 @@ function ImageCaptureReporter(baseReporterDecorator, config, logger, emitter) {
referenceRun = false
} = config;

/**
* Basic pretty-print SVG, each tag on a new line.
* @param {String} svg The SVG
* @return {String} Pretty SVG
*/
function prettyXML(svg) {
svg = svg
.replace(/>/g, '>\n')

// Don't introduce newlines inside tspans or links, it will make the text
// render differently
.replace(/<tspan([^>]*)>\n/g, '<tspan$1>')
.replace(/<\/tspan>\n/g, '</tspan>')
.replace(/<a([^>]*)>\n/g, '<a$1>')
.replace(/<\/a>\n/g, '</a>');

return svg;
}

/**
* Create an animated gif of the reference and the candidata image, in order to
* see the differences.
Expand Down Expand Up @@ -158,7 +139,7 @@ function ImageCaptureReporter(baseReporterDecorator, config, logger, emitter) {
try {
if (/\.svg$/.test(filename)) {
pendingFileWritings++;
fs.writeFile(filename, prettyXML(data), err => {
fs.writeFile(filename, data, err => {
if (err) {
throw err;
}
Expand Down
22 changes: 21 additions & 1 deletion test/karma-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,25 @@ Highcharts.prepareShot = function (chart) {
}
};

/**
* Basic pretty-print SVG, each tag on a new line.
* @param {String} svg The SVG
* @return {String} Pretty SVG
*/
function prettyXML(svg) {
svg = svg
.replace(/>/g, '>\n')

// Don't introduce newlines inside tspans or links, it will make the text
// render differently
.replace(/<tspan([^>]*)>\n/g, '<tspan$1>')
.replace(/<\/tspan>\n/g, '</tspan>')
.replace(/<a([^>]*)>\n/g, '<a$1>')
.replace(/<\/a>\n/g, '</a>');

return svg;
}

/**
* Get the SVG of a chart, or the first SVG in the page
* @param {Object} chart The chart
Expand Down Expand Up @@ -445,7 +464,8 @@ function getSVG(chart) {
svg = document.getElementsByTagName('svg')[0].outerHTML;
}
}
return svg;

return prettyXML(svg);
}

/**
Expand Down

0 comments on commit c6c2574

Please sign in to comment.