Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add --list-reporters option and reporters info string support

  • Loading branch information...
commit 44230d534fbf29413bd11b78aa6549e046f6bf1e 1 parent 2fda988
@Sannis Sannis authored
View
1  README.md
@@ -219,6 +219,7 @@ assertions as the exit code. Exiting with 0 when all tests pass.
* __--reporter FILE__ - you can set the test reporter to a custom module or
on of the modules in nodeunit/lib/reporters, when omitted, the default test runner
is used.
+* __--list-reporters__ - list available build-in reporters.
* __--config FILE__ - load config options from a JSON file, allows
the customisation of color schemes for the default test reporter etc. See
bin/nodeunit.json for current available options.
View
18 bin/nodeunit
@@ -19,6 +19,7 @@ var usage = "Usage: nodeunit [options] testmodule1.js testfolder [...] \n" +
"Options:\n\n" +
" --config FILE the path to a JSON file with options\n" +
" --reporter FILE optional path to a reporter file to customize the output\n" +
+ " --list-reporters list available build-in reporters\n" +
" -h, --help display this help and exit\n" +
" -v, --version output version information and exit";
@@ -38,10 +39,25 @@ args.forEach(function (arg) {
} else if (reporter_param_found) {
reporter_file = arg;
reporter_param_found = false;
+ } else if (arg === '--list-reporters') {
+ var reporters = fs.readdirSync(__dirname + '/../lib/reporters');
+ reporters = reporters.filter(function (reporter_file) {
+ return (/\.js$/).test(reporter_file);
+ }).map(function (reporter_file) {
+ return reporter_file.replace(/\.js$/, '');
+ }).filter(function (reporter_file) {
+ return reporter_file !== 'index';
+ });
+ sys.puts('Build-in reporters: ');
+ reporters.forEach(function (reporter_file) {
+ var reporter = require('../lib/reporters/' + reporter_file);
+ sys.puts(' * ' + reporter_file + (reporter.info ? ': ' + reporter.info : ''));
+ });
+ process.exit(0);
} else if ((arg === '-v') || (arg === '--version')) {
var content = fs.readFileSync(__dirname + '/../package.json', 'utf8');
var pkg = JSON.parse(content);
- console.log(pkg.version);
+ sys.puts(pkg.version);
process.exit(0);
} else if ((arg === '-h') || (arg === '--help')) {
sys.puts(usage);
View
3  doc/nodeunit.md
@@ -26,6 +26,9 @@ Nodeunit is a simple unit testing tool based on the node.js assert module.
You can set the test reporter to a custom module or on of the modules
in nodeunit/lib/reporters, when omitted, the default test runner is used.
+ __--list-reporters__:
+ List available build-in reporters.
+
__-h__, __--help__:
Display the help and exit.
View
6 lib/reporters/default.js
@@ -15,6 +15,12 @@ var nodeunit = require('../nodeunit'),
AssertionError = require('assert').AssertionError;
/**
+ * Reporter info string
+ */
+
+exports.info = "Default tests reporter";
+
+/**
* Run all tests within each module, reporting the results to the command-line.
*
* @param {Array} files
View
6 lib/reporters/html.js
@@ -15,6 +15,12 @@ var nodeunit = require('../nodeunit'),
AssertionError = require('assert').AssertionError;
/**
+ * Reporter info string
+ */
+
+exports.info = "Report tests result as HTML";
+
+/**
* Run all tests within each module, reporting the results to the command-line.
*
* @param {Array} files
View
6 lib/reporters/minimal.js
@@ -15,6 +15,12 @@ var nodeunit = require('../nodeunit'),
AssertionError = require('assert').AssertionError;
/**
+ * Reporter info string
+ */
+
+exports.info = "Pretty minimal output";
+
+/**
* Run all tests within each module, reporting the results to the command-line.
*
* @param {Array} files
View
6 lib/reporters/skip_passed.js
@@ -15,6 +15,12 @@ var nodeunit = require('../nodeunit'),
AssertionError = require('assert').AssertionError;
/**
+ * Reporter info string
+ */
+
+exports.info = "Skip passed tests output";
+
+/**
* Run all tests within each module, reporting the results to the command-line.
*
* @param {Array} files
View
6 man1/nodeunit.1
@@ -49,6 +49,12 @@ Allows the use of mocks and stubs
in nodeunit/lib/reporters, when omitted, the default test runner is used\.
.
.P
+ \fB\-\-list\-reporters\fR:
+.
+.br
+ List available build\-in reporters\.
+.
+.P
\fB\-h\fR, \fB\-\-help\fR:
.
.br
Please sign in to comment.
Something went wrong with that request. Please try again.