Permalink
Browse files

Prepping for npm installation, added 100ms super-smelly timeout for p…

…rinter termination, while looking into better ways...
  • Loading branch information...
lukebayes committed Feb 23, 2011
1 parent c5e98ca commit b82492eaaea4b9d784dad3593b559318dec7e28a
Showing with 34 additions and 31 deletions.
  1. +0 −23 bin/nodeshould.js
  2. +8 −0 cli.js
  3. +7 −0 package.json
  4. +1 −1 src/node_should/printer.js
  5. +18 −7 src/node_should/runner.js
View
@@ -1,23 +0,0 @@
-
-/**
- * Run this file with:
- *
- * nodeshould -s sources \
- * -s lib/foo \
- * -s lib/bar \
- * -t '/test-*.js/' \
- * -n '/should make happy/'
- *
- * @param s Directories that contain code that can be required. If a directory
- * is found at ./src or ./test, those directories will be automatically added
- * to the load path.
- * @param t Regular Expression that matches the test file or files that you
- * want to load.
- * @param n Regular Expression that matches the test label(s) that you want
- * to execute.
- */
-
-var Runner = require('node_should').Runner;
-var runner = new Runner();
-runner.runFromTerminal(process.argv);
-
View
8 cli.js
@@ -0,0 +1,8 @@
+#!/usr/bin/env node
+
+require.paths.unshift('./src');
+
+var Runner = require('node_should').Runner;
+var runner = new Runner();
+runner.runFromTerminal(process.argv.slice(2));
+
View
@@ -9,6 +9,13 @@
"email" : "lbayes@patternpark.com",
"url" : "http://lukebayes.com",
},
+ "repository" : {
+ "type" : "git",
+ "url" : "https://github.com/lukebayes/node-should",
+ },
+ "bin" : { "nodeshould" : "./cli.js" },
+ "directories" : ["src"],
"main" : "node_should.js",
"test" : "runner.js",
+ "engines" : { "node" : ">= 0.4.0" },
}
@@ -89,7 +89,7 @@ Printer.prototype._contextCompleteHandler = function(context) {
if (self.contexts.length == 0) {
self.finish();
}
- }, 1);
+ }, 100);
}
Printer.prototype.testIgnoreHandler = function(test, message) {
View
@@ -6,14 +6,13 @@ var vm = require('vm');
var readEachFileMatching = require('node_should/util').readEachFileMatching;
var DEFAULT_EXPRESSION = /_test.js$/;
-var DEFAULT_PATH = './test';
+var DEFAULT_PATHS = ['./test'];
var DEFAULT_PRINTERS = [new Printer()];
var Runner = function() {
}
Runner.prototype.runFromTerminal = function(argv, printers, completeHandler) {
- console.log("Running from term with: " + argv);
argv.forEach(function(val, index, array) {
console.log("val: " + val + " index: " + index);
if (val == '-s' || val == '--source-path') {
@@ -24,19 +23,31 @@ Runner.prototype.runFromTerminal = function(argv, printers, completeHandler) {
console.log("test name with: " + array[index+1]);
}
});
+ this.run();
}
-Runner.prototype.run = function(expr, path, printers, completeHandler) {
+Runner.prototype.run = function(expr, paths, printers, completeHandler) {
printers = (printers) ? printers : DEFAULT_PRINTERS;
// start provided printers:
printers.forEach(function(p) { p.start(); });
expr = (expr) ? expr : DEFAULT_EXPRESSION;
- path = (path) ? path : DEFAULT_PATH;
+ paths = (paths) ? paths : DEFAULT_PATHS;
+
+ this._addToLoadPath(paths);
+
var self = this;
- readEachFileMatching(expr, path, function(err, file, content) {
- if (err) throw err;
- self._runFileContent(file, content, printers, completeHandler);
+ paths.forEach(function(path) {
+ readEachFileMatching(expr, path, function(err, file, content) {
+ if (err) throw err;
+ self._runFileContent(file, content, printers, completeHandler);
+ });
+ });
+}
+
+Runner.prototype._addToLoadPath = function(paths) {
+ paths.forEach(function(path) {
+ require.paths.unshift(path);
});
}

0 comments on commit b82492e

Please sign in to comment.