Skip to content

Commit

Permalink
_mocha: Allow boolean --reporter-options
Browse files Browse the repository at this point in the history
Previously "mocha --reporter-options foo" would blow up because an equal sign is required. This is quite unhandy for reporters that need to accept boolean (flag-ish) options.

This commit changes that so that a value-less reporter option will be interpreted as having a value of true.

This means that --reporter-options foo=bar,quux will turn into { foo: 'bar', quux: true }
  • Loading branch information
papandreou committed Jun 18, 2015
1 parent 44b0045 commit 6379414
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions bin/_mocha
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,13 @@ var reporterOptions = {};
if (program.reporterOptions !== undefined) {
program.reporterOptions.split(",").forEach(function(opt) {
var L = opt.split("=");
if (L.length != 2) {
if (L.length > 2 || L.length === 0) {
throw new Error("invalid reporter option '" + opt + "'");
} else if (L.length === 2) {
reporterOptions[L[0]] = L[1];
} else {
reporterOptions[L[0]] = true;
}
reporterOptions[L[0]] = L[1];
});
}

Expand Down

0 comments on commit 6379414

Please sign in to comment.