Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 44230d534fbf29413bd11b78aa6549e046f6bf1e 1 parent 2fda988
Oleg Efimov Sannis authored
1  README.md
Source Rendered
@@ -219,6 +219,7 @@ assertions as the exit code. Exiting with 0 when all tests pass.
219 219 * __--reporter FILE__ - you can set the test reporter to a custom module or
220 220 on of the modules in nodeunit/lib/reporters, when omitted, the default test runner
221 221 is used.
  222 +* __--list-reporters__ - list available build-in reporters.
222 223 * __--config FILE__ - load config options from a JSON file, allows
223 224 the customisation of color schemes for the default test reporter etc. See
224 225 bin/nodeunit.json for current available options.
18 bin/nodeunit
@@ -19,6 +19,7 @@ var usage = "Usage: nodeunit [options] testmodule1.js testfolder [...] \n" +
19 19 "Options:\n\n" +
20 20 " --config FILE the path to a JSON file with options\n" +
21 21 " --reporter FILE optional path to a reporter file to customize the output\n" +
  22 + " --list-reporters list available build-in reporters\n" +
22 23 " -h, --help display this help and exit\n" +
23 24 " -v, --version output version information and exit";
24 25
@@ -38,10 +39,25 @@ args.forEach(function (arg) {
38 39 } else if (reporter_param_found) {
39 40 reporter_file = arg;
40 41 reporter_param_found = false;
  42 + } else if (arg === '--list-reporters') {
  43 + var reporters = fs.readdirSync(__dirname + '/../lib/reporters');
  44 + reporters = reporters.filter(function (reporter_file) {
  45 + return (/\.js$/).test(reporter_file);
  46 + }).map(function (reporter_file) {
  47 + return reporter_file.replace(/\.js$/, '');
  48 + }).filter(function (reporter_file) {
  49 + return reporter_file !== 'index';
  50 + });
  51 + sys.puts('Build-in reporters: ');
  52 + reporters.forEach(function (reporter_file) {
  53 + var reporter = require('../lib/reporters/' + reporter_file);
  54 + sys.puts(' * ' + reporter_file + (reporter.info ? ': ' + reporter.info : ''));
  55 + });
  56 + process.exit(0);
41 57 } else if ((arg === '-v') || (arg === '--version')) {
42 58 var content = fs.readFileSync(__dirname + '/../package.json', 'utf8');
43 59 var pkg = JSON.parse(content);
44   - console.log(pkg.version);
  60 + sys.puts(pkg.version);
45 61 process.exit(0);
46 62 } else if ((arg === '-h') || (arg === '--help')) {
47 63 sys.puts(usage);
3  doc/nodeunit.md
Source Rendered
@@ -26,6 +26,9 @@ Nodeunit is a simple unit testing tool based on the node.js assert module.
26 26 You can set the test reporter to a custom module or on of the modules
27 27 in nodeunit/lib/reporters, when omitted, the default test runner is used.
28 28
  29 + __--list-reporters__:
  30 + List available build-in reporters.
  31 +
29 32 __-h__, __--help__:
30 33 Display the help and exit.
31 34
6 lib/reporters/default.js
@@ -15,6 +15,12 @@ var nodeunit = require('../nodeunit'),
15 15 AssertionError = require('assert').AssertionError;
16 16
17 17 /**
  18 + * Reporter info string
  19 + */
  20 +
  21 +exports.info = "Default tests reporter";
  22 +
  23 +/**
18 24 * Run all tests within each module, reporting the results to the command-line.
19 25 *
20 26 * @param {Array} files
6 lib/reporters/html.js
@@ -15,6 +15,12 @@ var nodeunit = require('../nodeunit'),
15 15 AssertionError = require('assert').AssertionError;
16 16
17 17 /**
  18 + * Reporter info string
  19 + */
  20 +
  21 +exports.info = "Report tests result as HTML";
  22 +
  23 +/**
18 24 * Run all tests within each module, reporting the results to the command-line.
19 25 *
20 26 * @param {Array} files
6 lib/reporters/minimal.js
@@ -15,6 +15,12 @@ var nodeunit = require('../nodeunit'),
15 15 AssertionError = require('assert').AssertionError;
16 16
17 17 /**
  18 + * Reporter info string
  19 + */
  20 +
  21 +exports.info = "Pretty minimal output";
  22 +
  23 +/**
18 24 * Run all tests within each module, reporting the results to the command-line.
19 25 *
20 26 * @param {Array} files
6 lib/reporters/skip_passed.js
@@ -15,6 +15,12 @@ var nodeunit = require('../nodeunit'),
15 15 AssertionError = require('assert').AssertionError;
16 16
17 17 /**
  18 + * Reporter info string
  19 + */
  20 +
  21 +exports.info = "Skip passed tests output";
  22 +
  23 +/**
18 24 * Run all tests within each module, reporting the results to the command-line.
19 25 *
20 26 * @param {Array} files
6 man1/nodeunit.1
@@ -49,6 +49,12 @@ Allows the use of mocks and stubs
49 49 in nodeunit/lib/reporters, when omitted, the default test runner is used\.
50 50 .
51 51 .P
  52 + \fB\-\-list\-reporters\fR:
  53 +.
  54 +.br
  55 + List available build\-in reporters\.
  56 +.
  57 +.P
52 58 \fB\-h\fR, \fB\-\-help\fR:
53 59 .
54 60 .br

0 comments on commit 44230d5

Please sign in to comment.
Something went wrong with that request. Please try again.