Skip to content

Commit

Permalink
add support for reporter options
Browse files Browse the repository at this point in the history
  • Loading branch information
demmer committed Jul 12, 2014
1 parent 913964d commit 7ce102b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
16 changes: 15 additions & 1 deletion bin/_mocha
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ program
.option('-A, --async-only', "force all tests to take a callback (async)")
.option('-C, --no-colors', 'force disabling of colors')
.option('-G, --growl', 'enable growl notification support')
.option('-O, --reporter-options <k=v,k2=v2,...>', 'reporter-specific options')
.option('-R, --reporter <name>', 'specify the reporter to use', 'spec')
.option('-S, --sort', "sort test files")
.option('-b, --bail', "bail after first test failure")
Expand Down Expand Up @@ -190,9 +191,22 @@ program.parse(process.argv);

Error.stackTraceLimit = Infinity; // TODO: config

// reporter options

var reporterOptions = {};
if (program.reporterOptions !== undefined) {
program.reporterOptions.split(",").forEach(function(opt) {
var L = opt.split("=");
if (L.length != 2) {
throw new Error("invalid reporter option '" + opt + "'");
}
reporterOptions[L[0]] = L[1];
});
}

// reporter

mocha.reporter(program.reporter);
mocha.reporter(program.reporter, reporterOptions);

// interface

Expand Down
7 changes: 4 additions & 3 deletions lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function Mocha(options) {
this.suite = new exports.Suite('', new exports.Context);
this.ui(options.ui);
this.bail(options.bail);
this.reporter(options.reporter);
this.reporter(options.reporter, options.reporterOptions);
if (null != options.timeout) this.timeout(options.timeout);
this.useColors(options.useColors)
if (options.slow) this.slow(options.slow);
Expand Down Expand Up @@ -119,10 +119,10 @@ Mocha.prototype.addFile = function(file){
* Set reporter to `reporter`, defaults to "spec".
*
* @param {String|Function} reporter name or constructor
* @param {Object} reporterOptions optional options
* @api public
*/

Mocha.prototype.reporter = function(reporter){
Mocha.prototype.reporter = function(reporter, reporterOptions){
if ('function' == typeof reporter) {
this._reporter = reporter;
} else {
Expand All @@ -137,6 +137,7 @@ Mocha.prototype.reporter = function(reporter){
if (!_reporter) throw new Error('invalid reporter "' + reporter + '"');
this._reporter = _reporter;
}
this.options.reporterOptions = reporterOptions;
return this;
};

Expand Down

0 comments on commit 7ce102b

Please sign in to comment.