Skip to content

Commit

Permalink
- Revert the change of command line interface, --reporters is back to…
Browse files Browse the repository at this point in the history
… --reporter and --list-reporters

is back to --reporters.
- Use the "list" arguments parser for --reporter now.
- Mocha.reporters does not accept a comma-separated string of reporter names anymore, this is the command line parser's job
to parse the --reporter command line switch and provide an array to this function.
  • Loading branch information
Julien Gilli committed Jul 20, 2013
1 parent c4bc798 commit 5f3cbe9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 26 deletions.
26 changes: 13 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ test-jsapi:

test-unit:
@./bin/mocha \
--reporters $(REPORTER) \
--reporter $(REPORTER) \
test/acceptance/*.js \
--growl \
test/*.js

test-compilers:
@./bin/mocha \
--reporters $(REPORTER) \
--reporter $(REPORTER) \
--compilers coffee:coffee-script,foo:./test/compiler/foo \
test/acceptance/test.coffee \
test/acceptance/test.foo

test-requires:
@./bin/mocha \
--reporters $(REPORTER) \
--reporter $(REPORTER) \
--compilers coffee:coffee-script \
--require test/acceptance/require/a.js \
--require test/acceptance/require/b.coffee \
Expand All @@ -63,50 +63,50 @@ test-requires:

test-bdd:
@./bin/mocha \
--reporters $(REPORTER) \
--reporter $(REPORTER) \
--ui bdd \
test/acceptance/interfaces/bdd

test-tdd:
@./bin/mocha \
--reporters $(REPORTER) \
--reporter $(REPORTER) \
--ui tdd \
test/acceptance/interfaces/tdd

test-qunit:
@./bin/mocha \
--reporters $(REPORTER) \
--reporter $(REPORTER) \
--ui qunit \
test/acceptance/interfaces/qunit

test-exports:
@./bin/mocha \
--reporters $(REPORTER) \
--reporter $(REPORTER) \
--ui exports \
test/acceptance/interfaces/exports

test-grep:
@./bin/mocha \
--reporters $(REPORTER) \
--reporter $(REPORTER) \
--grep fast \
test/acceptance/misc/grep

test-invert:
@./bin/mocha \
--reporters $(REPORTER) \
--reporter $(REPORTER) \
--grep slow \
--invert \
test/acceptance/misc/grep

test-bail:
@./bin/mocha \
--reporters $(REPORTER) \
--reporter $(REPORTER) \
--bail \
test/acceptance/misc/bail

test-async-only:
@./bin/mocha \
--reporters $(REPORTER) \
--reporter $(REPORTER) \
--async-only \
test/acceptance/misc/asyncOnly

Expand All @@ -115,7 +115,7 @@ test-glob:

non-tty:
@./bin/mocha \
--reporters dot \
--reporter dot \
test/acceptance/interfaces/bdd 2>&1 > /tmp/dot.out

@echo dot:
Expand All @@ -129,7 +129,7 @@ non-tty:
@cat /tmp/list.out

@./bin/mocha \
--reporters spec \
--reporter spec \
test/acceptance/interfaces/bdd 2>&1 > /tmp/spec.out

@echo spec:
Expand Down
8 changes: 4 additions & 4 deletions bin/_mocha
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ program
.version(JSON.parse(fs.readFileSync(__dirname + '/../package.json', 'utf8')).version)
.usage('[debug] [options] [files]')
.option('-r, --require <name>', 'require the given module')
.option('-R, --reporters <name>,...', 'specify the reporters to use', ['dot'])
.option('-R, --reporter <name>,...', 'specify the reporters to use', list, ['dot'])
.option('-u, --ui <name>', 'specify user-interface (bdd|tdd|exports)', 'bdd')
.option('-g, --grep <pattern>', 'only run tests matching <pattern>')
.option('-i, --invert', 'inverts --grep matches')
Expand All @@ -82,7 +82,7 @@ program
.option('--globals <names>', 'allow the given comma-delimited global [names]', list, [])
.option('--check-leaks', 'check for global variable leaks')
.option('--interfaces', 'display available interfaces')
.option('--list-reporters', 'display available reporters')
.option('--reporters', 'display available reporters')
.option('--compilers <ext>:<module>,...', 'use the given module(s) to compile files', list, [])

program.name = 'mocha';
Expand Down Expand Up @@ -113,7 +113,7 @@ program.on('globals', function(val){

// --reporters

program.on('list-reporters', function(){
program.on('reporters', function(){
console.log();
console.log(' dot - dot matrix');
console.log(' doc - html documentation');
Expand Down Expand Up @@ -181,7 +181,7 @@ Error.stackTraceLimit = Infinity; // TODO: config

// reporter

mocha.reporters(program.reporters);
mocha.reporters(program.reporter);

// interface

Expand Down
14 changes: 6 additions & 8 deletions lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ Mocha.prototype.addFile = function(file){
/**
* Set reporters to `reporters`, defaults to "dot".
*
* @param {String|Function|Array of string|Array of functions} comma separated list
* of reporter names as string, array of constructors, reporter name as string or
* reporter constructor
* @param {String|Function|Array of strings|Array of functions} reporter name as string,
* reporter constructor, or array of constructors or reporter names as strings.
* @api public
*/

Expand All @@ -116,13 +115,12 @@ Mocha.prototype.reporters = function(reporters) {
// if no reporter is given as input, default to dot reporter
reporters = reporters || 'dot';

// turn reporters into a list of reporter names
// that we'll iterate on right after to initialize them
// If reporters argument is not a list, turn it into a list of reporter names
// or constructors that we'll iterate on right after to initialize them
reportersList = reporters;
if (!Array.isArray(reporters)) {
if ('string' == typeof reporters) {
reportersList = reporters.split(',');
} else if ('function' == typeof reporters) {
if (('string' == typeof reporters) ||
('function' == typeof reporters)) {
reportersList = [reporters];
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--require should
--reporters dot
--reporter dot
--ui bdd
--globals okGlobalA,okGlobalB
--globals okGlobalC
Expand Down

0 comments on commit 5f3cbe9

Please sign in to comment.