Skip to content

Commit

Permalink
added support for running single specific tests using their fully qua…
Browse files Browse the repository at this point in the history
…lified name, built as : 'outerGroup - .. - innerGroup - testName
  • Loading branch information
urigolani committed Jan 3, 2012
1 parent 92d7bd1 commit 3bfe5b7
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 4 deletions.
8 changes: 8 additions & 0 deletions bin/nodeunit
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ var testrunner,
reporter_file = 'default',
reporter_param_found = false,
testspec_param_found = false;
testFullSpec_param_found = false;

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" +
" -t name, specify a test to run\n" +
" -f fullname, specify a specific test to run. fullname is built so: \"outerGroup - .. - innerGroup - testName\"\n" +
" -h, --help display this help and exit\n" +
" -v, --version output version information and exit";



// load default options
Expand Down Expand Up @@ -65,6 +68,11 @@ args.forEach(function (arg) {
} else if (testspec_param_found) {
options.testspec = arg;
testspec_param_found = false;
} else if (arg === '-f') {
testFullSpec_param_found = true;
} else if (testFullSpec_param_found) {
options.testFullSpec= arg;
testFullSpec_param_found = false;
} else if (arg === '--list-reporters') {
var reporters = fs.readdirSync(__dirname + '/../lib/reporters');
reporters = reporters.filter(function (reporter_file) {
Expand Down
6 changes: 4 additions & 2 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ exports.runSuite = function (name, suite, opt, callback) {
};

if (typeof prop === 'function') {
var in_name = false;
var in_name = false,
in_specific_test = (_name.toString() === opt.testFullSpec) ? true : false;
for (var i = 0; i < _name.length; i += 1) {
if (_name[i] === opt.testspec) {
in_name = true;
}
}
if (!opt.testspec || in_name) {

if ((!opt.testFullSpec || in_specific_test) && (!opt.testspec || in_name)) {
if (opt.moduleStart) {
opt.moduleStart();
}
Expand Down
3 changes: 2 additions & 1 deletion lib/reporters/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ exports.run = function (files, options, callback) {
});

var opts = {
testspec: options.testspec,
testspec: options.testspec,
testFullSpec: options.testFullSpec,
moduleStart: function (name) {
console.log('\n' + bold(name));
},
Expand Down
1 change: 1 addition & 0 deletions lib/reporters/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ exports.run = function (files, options, callback) {
console.log('<body>');
nodeunit.runFiles(paths, {
testspec: options.testspec,
testFullSpec: options.testFullSpec,
moduleStart: function (name) {
console.log('<h2>' + name + '</h2>');
console.log('<ol>');
Expand Down
1 change: 1 addition & 0 deletions lib/reporters/junit.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ exports.run = function (files, opts, callback) {

nodeunit.runFiles(paths, {
testspec: opts.testspec,
testFullSpec: options.testFullSpec,
moduleStart: function (name) {
curModule = {
errorCount: 0,
Expand Down
1 change: 1 addition & 0 deletions lib/reporters/machineout.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ exports.run = function (files, options, callback) {

nodeunit.runFiles(paths, {
testspec: options.testspec,
testFullSpec: options.testFullSpec,
moduleStart: function (name) {},
testDone: function (name, assertions) {
tracker.remove(name);
Expand Down
3 changes: 2 additions & 1 deletion lib/reporters/minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ exports.run = function (files, options, callback) {
var start = new Date().getTime();

var opts = {
testspec: options.testspec,
testspec: options.testspec,
testFullSpec: options.testFullSpec,
moduleStart: function (name) {
process.stdout.write(bold(name) + ': ');
},
Expand Down
1 change: 1 addition & 0 deletions lib/reporters/nested.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ exports.run = function (files, options) {

nodeunit.runFiles(paths, {
testspec: options.testspec,
testFullSpec: options.testFullSpec,
moduleStart: function (name) {
console.log('\n' + bold(name));
},
Expand Down
1 change: 1 addition & 0 deletions lib/reporters/skip_passed.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ exports.run = function (files, options, callback) {

nodeunit.runFiles(paths, {
testspec: options.testspec,
testFullSpec: options.testFullSpec,
moduleStart: function (name) {
console.log('\n' + bold(name));
},
Expand Down
1 change: 1 addition & 0 deletions lib/reporters/verbose.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ exports.run = function (files, options) {

nodeunit.runFiles(paths, {
testspec: options.testspec,
testFullSpec: options.testFullSpec,
moduleStart: function (name) {
console.log('\n' + bold(name));
},
Expand Down

0 comments on commit 3bfe5b7

Please sign in to comment.