Muthu Kumar
6 years ago
3 changed files with 67 additions and 17 deletions
@ -1,22 +1,67 @@ |
|||||
const Readable = require('stream').Readable; |
const tag = (name, attrs, close, content) => { |
||||
const TAP = require('./tap'); |
const end = close ? "/>" : ">"; |
||||
const xUnitConverter = require('tap-xunit'); |
const pairs = []; |
||||
|
let tag; |
||||
const streamify = text => { |
|
||||
const s = new Readable(); |
Object.keys(attrs).forEach(key => { |
||||
s._read = () => {}; |
if (Object.prototype.hasOwnProperty.call(attrs, key)) { |
||||
s.push(text); |
pairs.push(key + '="' + (attrs[key]) + '"'); |
||||
s.push(null); |
} |
||||
return s; |
}); |
||||
|
|
||||
|
tag = "<" + name + (pairs.length ? " " + pairs.join(" ") : "") + end; |
||||
|
if (content) { |
||||
|
// content = content instanceof String ? content : escape(content);
|
||||
|
tag += content + "</" + name + end; |
||||
|
} |
||||
|
return new String(tag); |
||||
|
}; |
||||
|
|
||||
|
const convert = results => { |
||||
|
|
||||
|
const { count, success, failures, skipped } = results; |
||||
|
|
||||
|
return '<?xml version="1.0"?>' + tag( |
||||
|
'testsuites', |
||||
|
{}, |
||||
|
false, |
||||
|
tag( |
||||
|
'testsuite', |
||||
|
{ |
||||
|
tests: count, |
||||
|
success: success.length, |
||||
|
failures: failures.length, |
||||
|
skipped: skipped.length |
||||
|
}, |
||||
|
false, |
||||
|
results.reduce((acc, r) => { |
||||
|
const close = r.status === 'ok'; |
||||
|
const content = r.status !== 'ok' && |
||||
|
(r.status === 'skip' |
||||
|
? tag('skipped', {}, true) |
||||
|
: tag( |
||||
|
'failure', {}, |
||||
|
!r.reason, r.reason ? escape(r.reason) : '')); |
||||
|
acc += tag( |
||||
|
'testcase', |
||||
|
{ name: escape(r.description) }, |
||||
|
close, |
||||
|
content || '' |
||||
|
); |
||||
|
return acc; |
||||
|
}, '') |
||||
|
) |
||||
|
); |
||||
|
|
||||
}; |
}; |
||||
|
|
||||
const xunit = (runner) => { |
const xunit = runner => { |
||||
|
runner.on("end", results => { |
||||
|
|
||||
runner.on('end', results => |
console.log(convert(results)); |
||||
streamify(TAP.convert(results, { trace: false })) |
|
||||
.pipe(xUnitConverter()) |
|
||||
.pipe(process.stdout)); |
|
||||
|
|
||||
|
}); |
||||
}; |
}; |
||||
|
|
||||
module.exports = xunit; |
module.exports = xunit; |
||||
|
module.exports.convert = convert; |
||||
|
Loading…
Reference in new issue