Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

handle empty directories

  • Loading branch information...
commit e33bfadb8e9ad2fc109ed9e139e2f9287825793d 1 parent e44076f
@caolan authored
Showing with 34 additions and 2 deletions.
  1. +2 −2 README.md
  2. +6 −0 lib/nodeunit.js
  3. +26 −0 test/test-runfiles.js
View
4 README.md
@@ -135,7 +135,7 @@ deps, lib and test directories:
require.paths.push(__dirname);
require.paths.push(__dirname + '/deps');
- require.paths.push(__dirname + '/libs');
+ require.paths.push(__dirname + '/lib');
var testrunner = require('nodeunit').testrunner;
process.chdir(__dirname);
@@ -161,7 +161,7 @@ if its missing:
require.paths.push(__dirname);
require.paths.push(__dirname + '/deps');
- require.paths.push(__dirname + '/libs');
+ require.paths.push(__dirname + '/lib');
try {
var testrunner = require('nodeunit').testrunner;
View
6 lib/nodeunit.js
@@ -150,6 +150,12 @@ exports.runFiles = function(paths, options){
}
}, []);
+ if(!files.length){
+ var end = new Date().getTime();
+ (options.done || function(){})(assertions([], end-start));
+ return;
+ }
+
var i = 0;
var _fn = (function(file){
options.moduleStart(file);
View
26 test/test-runfiles.js
@@ -1,5 +1,7 @@
var assert = require('assert'),
sys = require('sys'),
+ fs = require('fs'),
+ path = require('path'),
nodeunit = require('nodeunit');
@@ -65,6 +67,29 @@ nodeunit.runFiles([], {
}
});
+
+var dir2 = __dirname + '/fixtures/dir2';
+var runfiles_emptydir_called = false;
+
+// git doesn't like empty directories, so we have to create one
+path.exists(dir2, function(exists){
+ if(!exists) fs.mkdirSync(dir2, 0777);
+
+ // runFiles on empty directory:
+ nodeunit.runFiles([dir2], {
+ moduleStart: function(){assert.ok(false, 'should not be called');},
+ testDone: function(){assert.ok(false, 'should not be called');},
+ testStart: function(){assert.ok(false, 'should not be called');},
+ log: function(){assert.ok(false, 'should not be called');},
+ done: function(assertions){
+ assert.equal(assertions.failures, 0, 'failures');
+ assert.equal(assertions.length, 0, 'length');
+ assert.ok(typeof assertions.duration == "number");
+ runfiles_emptydir_called = true;
+ }
+ });
+});
+
// restore runModule function
nodeunit.runModule = runModule_copy;
@@ -87,6 +112,7 @@ setTimeout(function(){
assert.equal(runModule_calls.length, 4);
assert.ok(runfiles_empty_called);
+ assert.ok(runfiles_emptydir_called);
sys.puts('test-runfiles OK');
Please sign in to comment.
Something went wrong with that request. Please try again.