Skip to content

Commit

Permalink
RFC: bin/run: Add --reporter-options
Browse files Browse the repository at this point in the history
This PR depends on tapjs/tap-mocha-reporter#49; review that first.

This is inspired by [Mocha's][1]:

```
  --reporter-options <k=v,k2=v2,...>
```

Except:

* I'm using a JSON value for easier parsing and more explicit typing.
  This will end up using a few more characters, but the format is more
  explicit than Mocha's (which only uses string values?).  And callers
  are likely to already be familiar with JSON, so we save the mental
  overhead of teaching them a new serialization format.

* I'm using a 'reporter' namespace.  This allows us to add other
  namespaces in the future to address other configurable aspects of
  tap-mocha-reporter's Formatter.  For example, we could use this
  same CLI option to configure the runner.

Somewhat related to this, if we have plans for allowing multiple
reporters [2], we may want to namespace *those* now.  For example:

```
  --reporter-options {"reporter": {"progress": {"open": "(", "close": ")"}}}
```

to avoid the issues Mocha bumped into [3] when trying to add multi-reporter support.

[1]: https://mochajs.org/#usage
[2]: tapjs#335
[3]: mochajs/mocha#2184 (comment)
  • Loading branch information
wking committed Jun 8, 2018
1 parent f323cdc commit 02ac8f3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
11 changes: 8 additions & 3 deletions bin/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const constructDefaultArgs = _ => {
timeout: +process.env.TAP_TIMEOUT || defaultTimeout,
color: !!colorSupport.level,
reporter: null,
reporterOptions: {},
files: [],
grep: [],
grepInvert: false,
Expand Down Expand Up @@ -282,6 +283,10 @@ const parseArgs = (args, options) => {
options.reporter = val || args[++i]
continue

case '--reporter-options':
options.reporterOptions = JSON.parse(val || args[++i])
continue

case '--gc': case '-gc': case '--expose-gc':
options.nodeArgs.push('--expose-gc')
continue
Expand Down Expand Up @@ -595,9 +600,9 @@ const setupTapEnv = options => {
const globFiles = files => files.reduce((acc, f) =>
acc.concat(f === '-' ? f : glob.sync(f, { nonull: true })), [])

const makeReporter = options =>
new (require('tap-mocha-reporter'))(options.reporter)

const makeReporter = options => {
return new (require('tap-mocha-reporter'))(options.reporter, {}, options.reporterOptions)
}
const stdinOnly = options => {
// if we didn't specify any files, then just passthrough
// to the reporter, so we don't get '/dev/stdin' in the suite list.
Expand Down
5 changes: 5 additions & 0 deletions bin/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ Options:
Available reporters:
@@REPORTERS@@

--reporter-options=<opts> Configure the specified reporter with a
JSON value. For example, you could use
'{"reporter": {"open": "(", "close": ")"}}'
to customize the progress reporter.

-o<file> Send the raw TAP output to the specified
--output-file=<file> file. Reporter output will still be
printed to stdout, but the file will
Expand Down
5 changes: 5 additions & 0 deletions docs/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ Options:
landing list markdown min nyan progress
silent spec tap xunit
--reporter-options=<opts> Configure the specified reporter with a
JSON value. For example, you could use
`{"reporter": {"open": "(", "close": ")"}}`
to customize the progress reporter.
-o<file> Send the raw TAP output to the specified
--output-file=<file> file. Reporter output will still be
printed to stdout, but the file will
Expand Down
8 changes: 8 additions & 0 deletions docs/reporting/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,11 @@ The following options are available:
- xunit

XML output popular in .NET land.

You can pass options to those reporters using `--reporter-options`
with a JSON value. For example:

```
--reporter=progress
--reporter-options='{"reporter": {"open": "(", "close": ")"}}'
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"signal-exit": "^3.0.0",
"source-map-support": "^0.5.6",
"stack-utils": "^1.0.0",
"tap-mocha-reporter": "^3.0.7",
"tap-mocha-reporter": "FIXME: bump to contain https://github.com/tapjs/tap-mocha-reporter/pull/49 once it lands",
"tap-parser": "^7.0.0",
"tmatch": "^4.0.0",
"trivial-deferred": "^1.0.1",
Expand Down

0 comments on commit 02ac8f3

Please sign in to comment.