Permalink
Browse files

adding nodeunit and make task to run all .test.js files, adding make …

…lint to package.json
  • Loading branch information...
1 parent 2e9fb37 commit bd4546ee16337a52391d8678e346f2c647a2e7e9 @paularmstrong paularmstrong committed Aug 6, 2011
Showing with 44 additions and 1 deletion.
  1. +1 −0 Makefile
  2. +3 −1 package.json
  3. +5 −0 scripts/config-test.js
  4. +35 −0 scripts/runtests.js
View
@@ -3,6 +3,7 @@ all:
test:
@node tests/tests.js
+ @node scripts/runtests.js
lint:
@node scripts/runlint.js
View
@@ -7,13 +7,15 @@
"author": "Dusko Jordanovski <jordanovskid@gmail.com>",
"dependencies": {},
"devDependencies": {
- "nodelint": "0.4.0"
+ "nodelint": "0.4.0",
+ "nodeunit": "0.5.3"
},
"main": "index",
"engines": {
"node": ">= 0.4.1"
},
"scripts": {
+ "lint": "make lint",
"test": "make test"
}
}
View
@@ -0,0 +1,5 @@
+module.exports = {
+ root: __dirname + '/../',
+ testRunner: 'default',
+ pathIgnore: ['*node_modules*']
+};
View
@@ -0,0 +1,35 @@
+require.paths.unshift(__dirname + '/../node_modules/');
+
+var util = require('util'),
+ child_process = require('child_process'),
+ nodeunit = require('nodeunit'),
+ configFile = __dirname + '/config-test',
+ ignore = '',
+ config, test_runner, i;
+
+process.argv.forEach(function (val, index, array) {
+ if (index < 2) {
+ return;
+ }
+
+ if (val === '-c') {
+ configFile = process.argv[~~index + 1];
+ }
+});
+
+config = require(configFile);
+test_runner = nodeunit.reporters[config.testRunner];
+
+function runTests(error, stdout, stderr) {
+ var tests = stdout.trim().split("\n");
+ if (tests.length && tests[0] !== '') {
+ test_runner.run(tests);
+ }
+}
+
+i = config.pathIgnore.length;
+while (i--) {
+ ignore += ' ! -path "' + config.pathIgnore[i] + '"';
+}
+
+child_process.exec('find . -name "*.test.js" ' + ignore, { cwd: config.root }, runTests);

0 comments on commit bd4546e

Please sign in to comment.