Skip to content

Commit

Permalink
move common code to superclass
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkot authored and rwaldron committed Nov 29, 2018
1 parent 0cbc375 commit 7f056fb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 52 deletions.
25 changes: 23 additions & 2 deletions lib/Reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,30 @@ const chalk = require('chalk');
module.exports = class Reporter {
constructor (options = {}) {
this.options = options;
this.source = undefined;
this.results = [];
}
start() {}
result(host, result) {}

start(source) {
this.source = source;

if (this.options.showSource) {
Reporter.printSource(source);
}
}

result(host, result) {
let resultCell = result.stdout.trim();
if (result.error) {
resultCell += '\n' + chalk.red(`${result.error.name}: ${result.error.message}`);
}
resultCell = resultCell.replace(/\r/g, '');

this.results.push([
host.name, resultCell
]);
}

end() {}

get isUnanimous() {
Expand Down
23 changes: 0 additions & 23 deletions lib/reporters/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,6 @@ const Reporter = require('../Reporter.js');
const chalk = require('chalk');

module.exports = class DefaultReporter extends Reporter {
constructor(options) {
super(options);
this.source = undefined;
this.results = [];
this.resultsMap = {};
}
start(source) {
this.source = source;

if (this.options.showSource) {
Reporter.printSource(source);
}
}
result(host, result) {
let resultString = result.stdout.trim();
if (result.error) {
resultString += chalk.red(`${result.error.name}: ${result.error.message}`);
}

this.results.push([
host.name, resultString
]);
}
end() {
if (this.options.unanimous && this.isUnanimous) {
process.exit(0);
Expand Down
27 changes: 0 additions & 27 deletions lib/reporters/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,6 @@ const chalk = require('chalk');
const Table = require('cli-table');

module.exports = class TableReporter extends Reporter {
constructor(options) {
super(options);
this.source = undefined;
this.results = [];
this.resultsMap = {};
}

start(source) {
this.source = source;

if (this.options.showSource) {
Reporter.printSource(source);
}
}

result(host, result) {
let resultCell = result.stdout.trim();
if (result.error) {
resultCell += '\n' + chalk.red(`${result.error.name}: ${result.error.message}`);
}
resultCell = resultCell.replace(/\r/g, '');

this.results.push([
host.name, resultCell
]);
}

end() {
if (this.options.unanimous && this.isUnanimous) {
process.exit(0);
Expand Down

0 comments on commit 7f056fb

Please sign in to comment.