Muthu Kumar
6 years ago
9 changed files with 151 additions and 116 deletions
@ -0,0 +1,52 @@ |
|||
const { eventMap, eventVerbs } = require('../util/constants'); |
|||
|
|||
const convert = x => x; |
|||
|
|||
const count = { |
|||
pass: 0, |
|||
fail: 0, |
|||
skip: 0, |
|||
collapse: function() { |
|||
return this.pass + this.fail + this.skip; |
|||
} |
|||
}; |
|||
|
|||
const clear = () => { |
|||
|
|||
// clear screen
|
|||
process.stdout.write('\u001b[2J'); |
|||
// set cursor position to top
|
|||
process.stdout.write('\u001b[1;1H'); |
|||
|
|||
}; |
|||
|
|||
const doneHandler = event => { |
|||
|
|||
clear(); |
|||
const mapEvent = eventMap[event.status]; |
|||
count[mapEvent]++; |
|||
console.log(`${count[mapEvent]} tests ${eventVerbs[mapEvent][2]}` |
|||
+ ` (total: ${count.collapse()})`); |
|||
|
|||
}; |
|||
|
|||
const Min = runner => { |
|||
|
|||
runner.on('start', () => console.log('Started tests')); |
|||
|
|||
runner.on('pass', doneHandler); |
|||
runner.on('fail', doneHandler); |
|||
runner.on('skip', doneHandler); |
|||
|
|||
runner.on('end', results => { |
|||
|
|||
clear(); |
|||
console.log(`Test suite ${results.name} has done running.`); |
|||
console.log('Success ratio:', results.successPercent, '%'); |
|||
|
|||
}); |
|||
|
|||
}; |
|||
|
|||
module.exports = Min; |
|||
module.exports.convert = convert; |
@ -1,72 +1,58 @@ |
|||
const tag = (name, attrs, close, content) => { |
|||
const end = close ? "/>" : ">"; |
|||
const pairs = []; |
|||
let tag; |
|||
|
|||
Object.keys(attrs).forEach(key => { |
|||
if (Object.prototype.hasOwnProperty.call(attrs, key)) { |
|||
pairs.push(key + '="' + (attrs[key]) + '"'); |
|||
} |
|||
}); |
|||
|
|||
tag = "<" + name + (pairs.length ? " " + pairs.join(" ") : "") + end; |
|||
if (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', |
|||
{ |
|||
name: results.name, |
|||
tests: count, |
|||
success: success.length, |
|||
failures: failures.length, |
|||
skipped: skipped.length, |
|||
timestamp: new Date().toUTCString(), |
|||
time: (results.duration / 1000) || 0, |
|||
}, |
|||
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 ? r.reason : '')); |
|||
acc += tag( |
|||
'testcase', |
|||
{ |
|||
name: r.description, |
|||
time: (r.duration / 1000) || 0, |
|||
}, |
|||
close, |
|||
content || '' |
|||
); |
|||
return acc; |
|||
}, '') |
|||
) |
|||
); |
|||
const toXML = require('jsontoxml'); |
|||
|
|||
const toJSON = resultsArray => { |
|||
|
|||
return { |
|||
testsuites: resultsArray.map(results => { |
|||
|
|||
const { name, count, success, failures, skipped } = results; |
|||
|
|||
return { |
|||
name: 'testsuite', |
|||
attrs: { |
|||
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 content = r.status !== 'ok' && |
|||
(r.status === 'skip' |
|||
? 'skipped' |
|||
: { |
|||
name: 'failure', |
|||
text: r.reason |
|||
? (r.reason && r.reason.stack) : '' |
|||
}); |
|||
acc.push({ |
|||
name: 'testcase', |
|||
attrs: { |
|||
name: r.description, |
|||
time: (r.duration / 1000) || 0, |
|||
}, |
|||
...(typeof content === 'object' |
|||
&& { text: content && content.stack }), |
|||
...(typeof content === 'object' |
|||
&& { children: [ content ]}), |
|||
}); |
|||
return acc; |
|||
}, []), |
|||
}; |
|||
|
|||
}) |
|||
}; |
|||
|
|||
}; |
|||
|
|||
const xunit = runner => { |
|||
runner.on("end", results => { |
|||
const convert = results => |
|||
toXML(toJSON(results), |
|||
{ xmlHeader: { standalone: true }}); |
|||
|
|||
console.log(convert(results)); |
|||
|
|||
}); |
|||
}; |
|||
const xunit = runner => |
|||
runner.on("end", results => console.log(convert([ results ]))); |
|||
|
|||
module.exports = xunit; |
|||
module.exports.convert = convert; |
|||
|
@ -1,8 +1,15 @@ |
|||
const chalk = require('chalk'); |
|||
const { EOL } = require('os'); |
|||
|
|||
module.exports = { |
|||
greenLine: chalk.green('------------------------------------'), |
|||
redLine: chalk.red('------------------------------------'), |
|||
EOL, |
|||
eventMap: { |
|||
'ok': 'pass', |
|||
'notOk': 'fail', |
|||
'skip': 'skip', |
|||
}, |
|||
eventVerbs: { |
|||
pass: [ 'pass', 'passing', 'passed' ], |
|||
fail: [ 'fail', 'failing', 'failed' ], |
|||
skip: [ 'skip', 'skipping', 'skipped' ], |
|||
}, |
|||
}; |
|||
|
Loading…
Reference in new issue