Permalink
Browse files

Fixed run_tests to run all tests within given directories recursively

  • Loading branch information...
1 parent b79de0f commit f4265df41ae7c57ca7a7af538dd78629f74d7fd0 @bbyars committed Jun 11, 2011
Showing with 33 additions and 13 deletions.
  1. +2 −2 Makefile
  2. +0 −4 TODO.md
  3. +27 −3 server/bin/run_tests
  4. +4 −4 server/test/testExtensions.js
View
@@ -25,10 +25,10 @@ java: start
test: unit_test functional_test
unit_test:
- port=$(PORT) server/bin/run_tests test/unit
+ port=$(PORT) server/bin/run_tests unit
functional_test: start
- port=$(PORT) server/bin/run_tests test/functional
+ port=$(PORT) server/bin/run_tests functional
lint:
find server -path 'server/deps' -prune -o \( -name "*.js" -o -name run_tests -o -name httpmock \) -print | xargs server/deps/nodelint/nodelint --config server/jslint.config
View
@@ -1,11 +1,7 @@
## Refactorings
-* filter out stub matching logic into module, unit test
* Remove string.format for something more javascript like
* Pass console.log around, allows using different logger
* Move the (path || '/') logic to repository
-* Fix run_tests to run protocol tests in nested directories
- * Allow passing 'unit' on command line and have it run all unit tests
-* Add mocking to testExtensions with a way of viewing actual arguments
## Build
* Pretty up github release page
View
@@ -2,7 +2,8 @@
// vim: ft=javascript
'use strict';
-var basedir = __dirname.replace(/\w+$/, '');
+var basedir = __dirname.replace(/\w+$/, ''),
+ fs = require('fs');
// nodeunit's default reporter depends on process.cwd
process.chdir(basedir);
@@ -13,10 +14,33 @@ require.paths.push(basedir);
require.paths.push(basedir + '/' + dir);
});
+function addDirectories(prefix, directory, collection) {
+ var root = prefix + directory,
+ files = fs.readdirSync(root),
+ file,
+ i;
+
+ collection.push(root);
+ for (i = 0; i < files.length; i += 1) {
+ file = root + '/' + files[i];
+ if (fs.statSync(file).isDirectory()) {
+ addDirectories(root + '/', files[i], collection);
+ }
+ }
+}
+
var tests = process.argv.slice(2);
if (tests.length === 0) {
- tests.push('test/unit');
- tests.push('test/functional');
+ addDirectories('./', 'test/unit', tests);
+ addDirectories('./', 'test/functional', tests);
+}
+else if (tests[0] === 'unit') {
+ tests.pop();
+ addDirectories('./', 'test/unit', tests);
+}
+else if (tests[0] === 'functional') {
+ tests.pop();
+ addDirectories('./', 'test/functional', tests);
}
var testrunner = require('nodeunit').reporters['default'];
@@ -93,20 +93,20 @@ function mock() {
actualArguments = [],
message = '';
- var stubFunction = function () {
+ function stubFunction() {
wasCalled = true;
actualArguments = Array.prototype.slice.call(arguments);
- };
+ }
- var setMessage = function (expected, actual) {
+ function setMessage(expected, actual) {
message = '\nExpected call with ' + expected;
if (wasCalled) {
message += '\nActual called with ' + actual;
}
else {
message += '\nNever called';
}
- };
+ }
stubFunction.wasCalled = function () {
return wasCalled;

0 comments on commit f4265df

Please sign in to comment.