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 toXML = require('jsontoxml'); |
||||
const end = close ? "/>" : ">"; |
|
||||
const pairs = []; |
const toJSON = resultsArray => { |
||||
let tag; |
|
||||
|
return { |
||||
Object.keys(attrs).forEach(key => { |
testsuites: resultsArray.map(results => { |
||||
if (Object.prototype.hasOwnProperty.call(attrs, key)) { |
|
||||
pairs.push(key + '="' + (attrs[key]) + '"'); |
const { name, count, success, failures, skipped } = results; |
||||
} |
|
||||
}); |
return { |
||||
|
name: 'testsuite', |
||||
tag = "<" + name + (pairs.length ? " " + pairs.join(" ") : "") + end; |
attrs: { |
||||
if (content) { |
name, |
||||
tag += content + "</" + name + end; |
tests: count, |
||||
} |
success: success.length, |
||||
return new String(tag); |
failures: failures.length, |
||||
}; |
skipped: skipped.length, |
||||
|
timestamp: new Date().toUTCString(), |
||||
const convert = results => { |
time: (results.duration / 1000) || 0, |
||||
|
}, |
||||
const { count, success, failures, skipped } = results; |
children: results.reduce((acc, r) => { |
||||
|
const content = r.status !== 'ok' && |
||||
return '<?xml version="1.0"?>' + tag( |
(r.status === 'skip' |
||||
'testsuites', |
? 'skipped' |
||||
{}, |
: { |
||||
false, |
name: 'failure', |
||||
tag( |
text: r.reason |
||||
'testsuite', |
? (r.reason && r.reason.stack) : '' |
||||
{ |
}); |
||||
name: results.name, |
acc.push({ |
||||
tests: count, |
name: 'testcase', |
||||
success: success.length, |
attrs: { |
||||
failures: failures.length, |
name: r.description, |
||||
skipped: skipped.length, |
time: (r.duration / 1000) || 0, |
||||
timestamp: new Date().toUTCString(), |
}, |
||||
time: (results.duration / 1000) || 0, |
...(typeof content === 'object' |
||||
}, |
&& { text: content && content.stack }), |
||||
false, |
...(typeof content === 'object' |
||||
results.reduce((acc, r) => { |
&& { children: [ content ]}), |
||||
const close = r.status === 'ok'; |
}); |
||||
const content = r.status !== 'ok' && |
return acc; |
||||
(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 xunit = runner => { |
const convert = results => |
||||
runner.on("end", 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 = xunit; |
||||
module.exports.convert = convert; |
module.exports.convert = convert; |
||||
|
@ -1,8 +1,15 @@ |
|||||
const chalk = require('chalk'); |
|
||||
const { EOL } = require('os'); |
const { EOL } = require('os'); |
||||
|
|
||||
module.exports = { |
module.exports = { |
||||
greenLine: chalk.green('------------------------------------'), |
|
||||
redLine: chalk.red('------------------------------------'), |
|
||||
EOL, |
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