Browse files

refactored cli parser, added makefile, tested instalation with npm

  • Loading branch information...
1 parent d2d3b00 commit 37f156c5ee338f9f81ce77e9827fbaab856e215e @kof committed Sep 26, 2010
View
9 .gitmodules
@@ -1,6 +1,9 @@
[submodule "deps/jscoverage"]
path = deps/jscoverage
url = http://github.com/visionmedia/node-jscoverage.git
-[submodule "deps/parseopts"]
- path = deps/parseopts
- url = http://github.com/mde/node-parseopts.git
+[submodule "./deps/argsparser"]
+ path = ./deps/argsparser
+ url = git@github.com:kof/node-argsparser.git
+[submodule "./deps/parseropts"]
+ path = ./deps/parseropts
+ url = git@github.com:kof/node-argsparser.git
View
13 Makefile
@@ -0,0 +1,13 @@
+install: jscoverage parseopts runtests
+
+jscoverage:
+ ./deps/jscoverage/configure && ./deps/jscoverage/make
+
+parseopts:
+ npm install ./deps/parseopts
+
+submodule:
+ git submodule update --init
+
+runtests:
+ ./bin/runtests
View
31 bin/cli
@@ -0,0 +1,31 @@
+#!/usr/bin/env node
+
+
+var sys = require( "sys" ),
+ //qunit = require( "qunit" ),
+ qunit = require( "./../lib/index" ),
+ args = require( "argsparser" ).parse();
+
+/**
+ * Camelize a string like --test-abc-def to --testAbcDef
+ *
+ */
+function camelize( str ) {
+ return str.split( "-" ).map( function( str, i ) {
+ if ( str ) {
+ return i === 2 ? str : str.substr(0, 1).toUpperCase() + str.substr(1);
+ }
+ }).join("");
+}
+
+Object.keys( args ).forEach( function( key ) {
+ args[camelize(key)] = qunit.options[camelize(key)] = args[key];
+ delete args[key];
+});
+
+if ( !args.code || !args.tests ) {
+ sys.print("test\n");
+ return;
+}
+
+qunit.run({ code: args.code, tests: args.tests });
View
6 bin/runtests
@@ -1,16 +1,16 @@
#!/usr/bin/env node
-var testrunner = require( "../lib/qunit/index" ),
+var testrunner = require( "../lib/index" ),
path = require( "path" ).normalize( __dirname + "/.." );
testrunner.run([
{
- code: path + "/lib/qunit/qunit.js",
+ code: path + "/lib/qunit.js",
tests: [ path + "/test/qunit.js", path + "/test/same.js"]
}
/* ,
{
- code: path + "/lib/qunit/index.js",
+ code: path + "/lib/index.js",
test: path + "/test/testrunner.js"
}
*/
1 deps/argsparser
@@ -0,0 +1 @@
+Subproject commit 982ad5a8baf34b938ac7c28b4453a23ff57bfba7
1 deps/parseopts
@@ -1 +0,0 @@
-Subproject commit b783a94addc70bd3e3e2c07df9f7e7931f815ed4
View
1 index.js
@@ -1 +0,0 @@
-module.exports = require('./lib/qunit/index.js');
View
0 lib/qunit/bootstrap.js → lib/bootstrap.js
File renamed without changes.
View
0 lib/qunit/coverage.js → lib/coverage.js
File renamed without changes.
View
23 lib/qunit/index.js → lib/index.js
@@ -131,6 +131,20 @@ function run( opts, report, callback ) {
}
/**
+ * Make an absolute path from relative
+ * @param {String} str
+ * @return {String}
+ */
+function absPath( str ) {
+
+ if ( str.substr( 0, 1 ) !== "/" ) {
+ str = path.join( process.cwd(), str );
+ }
+
+ return str;
+}
+
+/**
* Run tests in spawned node instance async for every test.
* @param {Object|Array} files
* @param {Function} callback optional
@@ -152,11 +166,16 @@ exports.run = function( files, callback ) {
files.forEach( function( opts ) {
opts = {
- code: opts.code,
+ code: absPath( opts.code ),
tests: typeof opts.tests === "string" ? [opts.tests] : opts.tests,
paths: opts.paths || options.paths,
coverage: opts.coverage || options.coverage
- };
+ };
+
+ // absolutize all urls
+ opts.tests = opts.tests.map( function( str ) {
+ return absPath( str );
+ });
function finished( cov ) {
if ( report.files < files.length ) {
View
0 lib/qunit/qunit.js → lib/qunit.js
File renamed without changes.
View
22 lib/qunit/cli.js
@@ -1,22 +0,0 @@
-var code = process.argv[2],
- test = process.argv[3],
- paths = process.argv[4],
- qunit = require( "./qunit" ),
- path = require( "path" );
-
-// add paths to require
-paths && require.paths.push.apply( require.paths, paths.split( "," ) );
-
-// make QUnit global
-global.QUnit = qunit.QUnit;
-
-// make qunit api global
-qunit.extend( global, QUnit.api );
-
-// require code
-qunit.extend( global, require( code.substr(0, code.length-3) ) );
-
-// require test
-require( test.substr(0, test.length-3) );
-
-QUnit.begin();
View
34 package.json
@@ -1,14 +1,24 @@
{
- "name": "node-qunit",
- "description": "Port of QUnit unit testing framework to nodejs",
- "version": "0.0.2",
- "author": "Oleg Slobodskoi <oleg008@gmail.com>",
- "contributors": [
- { "name": "John Resig", "email": "jeresig@gmail.com" },
- { "name": "Jörn Zaefferer"}
- ],
- "keywords": ["TDD", "QUnit", "unit testing", "tests"],
- "directories": { "lib": "./lib/qunit" },
- "bin": { "runtests": "./bin/runtests"},
- "engines": { "node": ">= 0.2.0" }
+ "name": "qunit",
+ "description": "A port of QUnit unit testing framework to nodejs",
+ "version": "0.0.3",
+ "author": "Oleg Slobodskoi <oleg008@gmail.com>",
+ "contributors": [
+ { "name": "John Resig", "email": "jeresig@gmail.com" },
+ { "name": "Jörn Zaefferer", "email": "joern.zaefferer@gmail.com" }
+ ],
+ "repository": {
+ "type": "git",
+ "url": "git@github.com:kof/node-qunit.git"
+ },
+ "keywords": [ "TDD", "QUnit", "unit testing", "tests" ],
+ "directories": { "lib": "./lib" },
+ "engines": { "node": ">= 0.2.0" },
+ "scripts": { "install": "make install" },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url" : "http://www.opensource.org/licenses/mit-license.php"
+ }
+ ]
}
View
32 readme.md
@@ -54,18 +54,20 @@ http://docs.jquery.com/QUnit
var testrunner = require( "qunit" );
- // set it to true if you want to report only errors
- testrunner.options.errorsOnly = false;
+ Defaults:
+
+ {
+ errorsOnly: false, // set it to true if you want to report only errors
+ errorStack: true, // set it to false if you want to get error stack in report
+ summary: true, // print a summary about all tested stuff after finish
+ coverage: true, // display coverage
+ paths: null // add paths to require of test environment
+ }
- // set it to false if you want to get error stack in report
- testrunner.options.errorStack = true;
-
- // print a summary about all tested stuff after finish
- testrunner.options.summary = true;
-
- // add paths to require of test environment
- testrunner.options.paths = require.paths;
+ // to change any option - change it :)
+ testrunner.options.optionName = value;
+
// one code and tests file
testrunner.run({
code: "/path/to/your/code.js",
@@ -164,10 +166,14 @@ Some tests examples
### CLI
- $ node cli.js /path/to/your/code.js /path/to/your/tests.js
+ $ ./bin/cli --code ./code.js --tests ./tests.js
+
+ // additionaly every option can be used
+ $ ./bin/cli --code ./code.js --tests ./tests.js --paths /path/for/require /path1/for/require
+
+ $ ./bin/cli --code ./code.js --tests ./tests.js --coverage false
- // add require.paths
- $ node cli.js /path/to/your/code.js /path/to/your/tests.js /path/for/require,/path1/for/require
+ $ ./bin/cli --code ./code.js --tests ./tests.js --summary false
## Run tests
$ ./bin/runtests

0 comments on commit 37f156c

Please sign in to comment.