Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve #22: --unanimous will exit(0) and output nothing if all hosts agree. #35

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions bin/eshost.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const yargv = yargs
.describe('showSource', 'show input source')
.boolean('showSource')
.alias('showSource', 'i')
.describe('unanimous', 'If all engines agree, exit(0) with no output, otherwise print and exit(1); implies --coalesce')
.boolean('unanimous')
.alias('unanimous', 'u')
.nargs('h', 1)
.describe('async', 'wait for realm destruction before reporting results')
.boolean('async')
Expand Down Expand Up @@ -72,6 +75,7 @@ const yargv = yargs
.example('eshost -h ch-*,node test.js')
.example('eshost -h ch-1.?.? test.js')
.example('eshost --tags latest test.js')
.example('eshost --unanimous test.js')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing -e or --eval

.fail(function (msg, err) {
if (err) {
console.error(err.stack);
Expand All @@ -83,6 +87,11 @@ const yargv = yargs

const argv = yargv.argv;

// --unanimous implies --coalesce
if (argv.unanimous) {
argv.coalesce = true;
}

let config;
if (argv.c) {
config = new Config(argv.c);
Expand Down Expand Up @@ -169,11 +178,10 @@ if (hosts.length === 0) {

let reporterOptions = {
showSource: argv.showSource,
coalesce: argv.coalesce
coalesce: argv.coalesce,
showSource: argv.showSource,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate key here.

unanimous: argv.unanimous
};
if (argv.showSource) {
reporterOptions.showSource = true;
}

let reporter;
if (argv.table) {
Expand Down
14 changes: 14 additions & 0 deletions lib/Reporter.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const chalk = require('chalk');

module.exports = class Reporter {
constructor (options = {}) {
this.options = options;
Expand Down Expand Up @@ -34,4 +36,16 @@ module.exports = class Reporter {
]);
}
}

static addTo(hostName, result) {
table.push([
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

table is undefined here. This can be fixed by changing the signature to match Reporter.coalesceInto(this.results, host, resultString, this.resultsMap, ", ");, ie. Reporter.addTo(this.results, host, resultString); and then addTo becomes:

  static addTo(table, host, result) {
    table.push([
      host.name, result
    ]);
  }

hostName, result
]);
}

static printSource(source) {
console.log(chalk.blue("## Source"));
console.log(source);
console.log("");
}
}
32 changes: 21 additions & 11 deletions lib/reporters/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ const Reporter = require('../Reporter.js');
const chalk = require('chalk');

module.exports = class DefaultReporter extends Reporter {
constructor (options) {
constructor(options) {
super(options);
this.source = undefined;
this.results = [];
this.resultsMap = {};
}
start(text) {
if (this.options.showSource) {
console.log(chalk.blue('## Source'));
console.log(text);
console.log("");
}
start(source) {
this.source = source;
}
result(host, result) {
let resultString = result.stdout.trim();
Expand All @@ -23,14 +20,27 @@ module.exports = class DefaultReporter extends Reporter {
if (this.options.coalesce) {
Reporter.coalesceInto(this.results, host, resultString, this.resultsMap, ", ");
} else {
printHostResult(host.name, resultString);
Reporter.addTo(host.name, resultString);
}
}
end() {
if (this.options.coalesce) {
this.results.forEach(row => {
printHostResult(row[0], row[1]);
})
if (this.options.unanimous && this.results.length == 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this logic, as the following results are unanimous, but would fail this check.

Given:

 eshost -u -e "1+1"

this.results might look like:

[ [ 'd8', '2' ], [ 'js', '2' ], [ 'ch', '2' ] ]

But that would fail this check and thus fail

If all engines under test produce identical output (logic already exists to test this in the collate option), print no output and set exit code to 0.

process.exit(0);
// don't print anything
} else {
if (this.options.showSource) {
Reporter.printSource(this.source);
}

this.results.forEach(row => {
printHostResult(row[0], row[1]);
})

if (this.options.unanimous) {
process.exit(1);
}
}
}
}
}
Expand Down
24 changes: 17 additions & 7 deletions lib/reporters/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ const Table = require('cli-table');
module.exports = class TableReporter extends Reporter {
constructor(options) {
super(options);
this.source = undefined;
this.results = new Table();
this.resultsMap = {};
}

start(text) {
if (this.options.showSource) {
console.log(chalk.blue('## Source'));
console.log(text);
console.log("");
}
start(source) {
this.source = source;
}

result(host, result) {
Expand All @@ -34,6 +31,19 @@ module.exports = class TableReporter extends Reporter {
}

end() {
console.log(this.results.toString());
if (this.options.unanimous && this.results.length == 1) {
process.exit(0);
// don't print anything
} else {
if (this.options.showSource) {
Reporter.printSource(this.source);
}

console.log(this.results.toString());

if (this.options.unanimous) {
process.exit(1);
}
}
}
}