Browse Source

[reporter] xUnit reporter escapes XML now

master
Muthu Kumar 6 years ago
parent
commit
b0f49dcc4d
  1. 23
      src/reporters/xunit.js

23
src/reporters/xunit.js

@ -1,6 +1,13 @@
const toXML = require('jsontoxml'); const toXML = require('jsontoxml');
const { clear } = require('../util/nodeutils'); const { clear } = require('../util/nodeutils');
const escapeXML = str =>
str
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
const toJSON = resultsArray => { const toJSON = resultsArray => {
return { return {
@ -11,7 +18,7 @@ const toJSON = resultsArray => {
return { return {
name: 'testsuite', name: 'testsuite',
attrs: { attrs: {
name, name: escapeXML(name),
tests: count, tests: count,
success: success.length, success: success.length,
failures: failures.length, failures: failures.length,
@ -20,20 +27,20 @@ const toJSON = resultsArray => {
time: (results.duration / 1000) || 0, time: (results.duration / 1000) || 0,
}, },
children: results.reduce((acc, r) => { children: results.reduce((acc, r) => {
const reason = r.reason ? (r.reason.stack || r.reason) : ''; const reason = r.reason
? (r.reason.stack || r.reason) : '';
const content = r.status !== 'ok' && const content = r.status !== 'ok' &&
r.status === 'skip' {
? { name: 'skipped', text: reason } name: r.status === 'skip' ? 'skipped' : 'failure',
: { name: 'failure', text: reason }; text: escapeXML(reason)
};
acc.push({ acc.push({
name: 'testcase', name: 'testcase',
attrs: { attrs: {
name: r.description, name: escapeXML(r.description),
time: (r.duration / 1000) || 0, time: (r.duration / 1000) || 0,
}, },
...(typeof content === 'object' ...(typeof content === 'object'
&& content),
...(typeof content === 'object'
&& { children: [ content ]}), && { children: [ content ]}),
}); });
return acc; return acc;

Loading…
Cancel
Save