Browse Source

[reporter] Minor refactor

master
Muthu Kumar 6 years ago
parent
commit
3838816327
  1. 5
      src/lib/testrunner.js
  2. 10
      src/reporters/min.js
  3. 3
      src/reporters/xunit.js
  4. 6
      src/runner/index.js
  5. 12
      src/util/nodeutils.js

5
src/lib/testrunner.js

@ -129,7 +129,10 @@ const testrunner = (instance) => {
reduceQueue, reduceQueue,
pick('results'), pick('results'),
)(instance)).then(results => { )(instance)).then(results => {
results.duration = Date.now() - perf.start; perf.end = Date.now();
results.end = perf.end.toUTCString();
results.start = perf.start.toUTCString();
results.duration = perf.end - perf.start;
return results; return results;
}); });

10
src/reporters/min.js

@ -1,4 +1,5 @@
const { eventMap, eventVerbs } = require('../util/constants'); const { eventMap, eventVerbs } = require('../util/constants');
const { clear } = require('../util/nodeutils');
const convert = x => x; const convert = x => x;
@ -11,15 +12,6 @@ const count = {
} }
}; };
const clear = () => {
// clear screen
process.stdout.write('\u001b[2J');
// set cursor position to top
process.stdout.write('\u001b[1;1H');
};
const doneHandler = event => { const doneHandler = event => {
clear(); clear();

3
src/reporters/xunit.js

@ -1,4 +1,5 @@
const toXML = require('jsontoxml'); const toXML = require('jsontoxml');
const { clear } = require('../util/nodeutils');
const toJSON = resultsArray => { const toJSON = resultsArray => {
@ -52,7 +53,7 @@ const convert = results =>
{ xmlHeader: { standalone: true }}); { xmlHeader: { standalone: true }});
const xunit = runner => const xunit = runner =>
runner.on("end", results => console.log(convert([ results ]))); runner.on("end", results => (clear(), console.log(convert([ results ]))));
module.exports = xunit; module.exports = xunit;
module.exports.convert = convert; module.exports.convert = convert;

6
src/runner/index.js

@ -26,6 +26,8 @@ const runner = instances => (options = {}) => {
if (RunInstances.length !== instances.length) if (RunInstances.length !== instances.length)
throw new Error (`Not all instances were of type ${type}`); throw new Error (`Not all instances were of type ${type}`);
const perf = { start: Date.now() };
return Promise.all(RunInstances.map(instance => { return Promise.all(RunInstances.map(instance => {
return ( return (
instance instance
@ -33,6 +35,10 @@ const runner = instances => (options = {}) => {
); );
})) }))
.then(results => { .then(results => {
perf.end = Date.now();
results.start = perf.start.toUTCString();
results.end = perf.end.toUTCString();
results.duration = perf.end - perf.start;
return options.request return options.request
? { ? {

12
src/util/nodeutils.js

@ -0,0 +1,12 @@
module.exports = {
clear: () => {
// clear screen
process.stdout.write('\u001b[2J');
// set cursor position to top
process.stdout.write('\u001b[1;1H');
},
};
Loading…
Cancel
Save