You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.4 KiB
63 lines
1.4 KiB
const toXML = require('jsontoxml');
|
|
const { clear } = require('../util/nodeutils');
|
|
|
|
const escapeXML = str =>
|
|
str
|
|
.replace(/&/g, '&')
|
|
.replace(/"/g, '"')
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>');
|
|
|
|
const toJSON = resultsArray => {
|
|
|
|
return {
|
|
testsuites: resultsArray.map(results => {
|
|
|
|
const { name, count, success, failures, skipped } = results;
|
|
|
|
return {
|
|
name: 'testsuite',
|
|
attrs: {
|
|
name: escapeXML(name),
|
|
tests: count,
|
|
success: success.length,
|
|
failures: failures.length,
|
|
skipped: skipped.length,
|
|
timestamp: new Date().toUTCString(),
|
|
time: (results.duration / 1000) || 0,
|
|
},
|
|
children: results.reduce((acc, r) => {
|
|
const reason = r.reason
|
|
? (r.reason.stack || r.reason) : '';
|
|
const content = r.status !== 'ok' &&
|
|
{
|
|
name: r.status === 'skip' ? 'skipped' : 'failure',
|
|
text: escapeXML(reason)
|
|
};
|
|
acc.push({
|
|
name: 'testcase',
|
|
attrs: {
|
|
name: escapeXML(r.description),
|
|
time: (r.duration / 1000) || 0,
|
|
},
|
|
...(typeof content === 'object'
|
|
&& { children: [ content ]}),
|
|
});
|
|
return acc;
|
|
}, []),
|
|
};
|
|
|
|
})
|
|
};
|
|
|
|
};
|
|
|
|
const convert = results =>
|
|
toXML(toJSON(results),
|
|
{ xmlHeader: { standalone: true }});
|
|
|
|
const xunit = runner =>
|
|
runner.on("end", results => (clear(), console.log(convert([ results ]))));
|
|
|
|
module.exports = xunit;
|
|
module.exports.convert = convert;
|
|
|