Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

refactored cli parser, added makefile, tested instalation with npm

  • Loading branch information...
commit 37f156c5ee338f9f81ce77e9827fbaab856e215e 1 parent d2d3b00
Oleg Slobodskoi authored
9 .gitmodules
... ... @@ -1,6 +1,9 @@
1 1 [submodule "deps/jscoverage"]
2 2 path = deps/jscoverage
3 3 url = http://github.com/visionmedia/node-jscoverage.git
4   -[submodule "deps/parseopts"]
5   - path = deps/parseopts
6   - url = http://github.com/mde/node-parseopts.git
  4 +[submodule "./deps/argsparser"]
  5 + path = ./deps/argsparser
  6 + url = git@github.com:kof/node-argsparser.git
  7 +[submodule "./deps/parseropts"]
  8 + path = ./deps/parseropts
  9 + url = git@github.com:kof/node-argsparser.git
13 Makefile
... ... @@ -0,0 +1,13 @@
  1 +install: jscoverage parseopts runtests
  2 +
  3 +jscoverage:
  4 + ./deps/jscoverage/configure && ./deps/jscoverage/make
  5 +
  6 +parseopts:
  7 + npm install ./deps/parseopts
  8 +
  9 +submodule:
  10 + git submodule update --init
  11 +
  12 +runtests:
  13 + ./bin/runtests
31 bin/cli
... ... @@ -0,0 +1,31 @@
  1 +#!/usr/bin/env node
  2 +
  3 +
  4 +var sys = require( "sys" ),
  5 + //qunit = require( "qunit" ),
  6 + qunit = require( "./../lib/index" ),
  7 + args = require( "argsparser" ).parse();
  8 +
  9 +/**
  10 + * Camelize a string like --test-abc-def to --testAbcDef
  11 + *
  12 + */
  13 +function camelize( str ) {
  14 + return str.split( "-" ).map( function( str, i ) {
  15 + if ( str ) {
  16 + return i === 2 ? str : str.substr(0, 1).toUpperCase() + str.substr(1);
  17 + }
  18 + }).join("");
  19 +}
  20 +
  21 +Object.keys( args ).forEach( function( key ) {
  22 + args[camelize(key)] = qunit.options[camelize(key)] = args[key];
  23 + delete args[key];
  24 +});
  25 +
  26 +if ( !args.code || !args.tests ) {
  27 + sys.print("test\n");
  28 + return;
  29 +}
  30 +
  31 +qunit.run({ code: args.code, tests: args.tests });
6 bin/runtests
... ... @@ -1,16 +1,16 @@
1 1 #!/usr/bin/env node
2 2
3   -var testrunner = require( "../lib/qunit/index" ),
  3 +var testrunner = require( "../lib/index" ),
4 4 path = require( "path" ).normalize( __dirname + "/.." );
5 5
6 6 testrunner.run([
7 7 {
8   - code: path + "/lib/qunit/qunit.js",
  8 + code: path + "/lib/qunit.js",
9 9 tests: [ path + "/test/qunit.js", path + "/test/same.js"]
10 10 }
11 11 /* ,
12 12 {
13   - code: path + "/lib/qunit/index.js",
  13 + code: path + "/lib/index.js",
14 14 test: path + "/test/testrunner.js"
15 15 }
16 16 */
1  deps/argsparser
... ... @@ -0,0 +1 @@
  1 +Subproject commit 982ad5a8baf34b938ac7c28b4453a23ff57bfba7
1  deps/parseopts
... ... @@ -1 +0,0 @@
1   -Subproject commit b783a94addc70bd3e3e2c07df9f7e7931f815ed4
1  index.js
... ... @@ -1 +0,0 @@
1   -module.exports = require('./lib/qunit/index.js');
0  lib/qunit/bootstrap.js → lib/bootstrap.js
File renamed without changes
0  lib/qunit/coverage.js → lib/coverage.js
File renamed without changes
23 lib/qunit/index.js → lib/index.js
@@ -131,6 +131,20 @@ function run( opts, report, callback ) {
131 131 }
132 132
133 133 /**
  134 + * Make an absolute path from relative
  135 + * @param {String} str
  136 + * @return {String}
  137 + */
  138 +function absPath( str ) {
  139 +
  140 + if ( str.substr( 0, 1 ) !== "/" ) {
  141 + str = path.join( process.cwd(), str );
  142 + }
  143 +
  144 + return str;
  145 +}
  146 +
  147 +/**
134 148 * Run tests in spawned node instance async for every test.
135 149 * @param {Object|Array} files
136 150 * @param {Function} callback optional
@@ -152,11 +166,16 @@ exports.run = function( files, callback ) {
152 166
153 167 files.forEach( function( opts ) {
154 168 opts = {
155   - code: opts.code,
  169 + code: absPath( opts.code ),
156 170 tests: typeof opts.tests === "string" ? [opts.tests] : opts.tests,
157 171 paths: opts.paths || options.paths,
158 172 coverage: opts.coverage || options.coverage
159   - };
  173 + };
  174 +
  175 + // absolutize all urls
  176 + opts.tests = opts.tests.map( function( str ) {
  177 + return absPath( str );
  178 + });
160 179
161 180 function finished( cov ) {
162 181 if ( report.files < files.length ) {
0  lib/qunit/qunit.js → lib/qunit.js
File renamed without changes
22 lib/qunit/cli.js
... ... @@ -1,22 +0,0 @@
1   -var code = process.argv[2],
2   - test = process.argv[3],
3   - paths = process.argv[4],
4   - qunit = require( "./qunit" ),
5   - path = require( "path" );
6   -
7   -// add paths to require
8   -paths && require.paths.push.apply( require.paths, paths.split( "," ) );
9   -
10   -// make QUnit global
11   -global.QUnit = qunit.QUnit;
12   -
13   -// make qunit api global
14   -qunit.extend( global, QUnit.api );
15   -
16   -// require code
17   -qunit.extend( global, require( code.substr(0, code.length-3) ) );
18   -
19   -// require test
20   -require( test.substr(0, test.length-3) );
21   -
22   -QUnit.begin();
34 package.json
... ... @@ -1,14 +1,24 @@
1 1 {
2   - "name": "node-qunit",
3   - "description": "Port of QUnit unit testing framework to nodejs",
4   - "version": "0.0.2",
5   - "author": "Oleg Slobodskoi <oleg008@gmail.com>",
6   - "contributors": [
7   - { "name": "John Resig", "email": "jeresig@gmail.com" },
8   - { "name": "Jörn Zaefferer"}
9   - ],
10   - "keywords": ["TDD", "QUnit", "unit testing", "tests"],
11   - "directories": { "lib": "./lib/qunit" },
12   - "bin": { "runtests": "./bin/runtests"},
13   - "engines": { "node": ">= 0.2.0" }
  2 + "name": "qunit",
  3 + "description": "A port of QUnit unit testing framework to nodejs",
  4 + "version": "0.0.3",
  5 + "author": "Oleg Slobodskoi <oleg008@gmail.com>",
  6 + "contributors": [
  7 + { "name": "John Resig", "email": "jeresig@gmail.com" },
  8 + { "name": "Jörn Zaefferer", "email": "joern.zaefferer@gmail.com" }
  9 + ],
  10 + "repository": {
  11 + "type": "git",
  12 + "url": "git@github.com:kof/node-qunit.git"
  13 + },
  14 + "keywords": [ "TDD", "QUnit", "unit testing", "tests" ],
  15 + "directories": { "lib": "./lib" },
  16 + "engines": { "node": ">= 0.2.0" },
  17 + "scripts": { "install": "make install" },
  18 + "licenses": [
  19 + {
  20 + "type": "MIT",
  21 + "url" : "http://www.opensource.org/licenses/mit-license.php"
  22 + }
  23 + ]
14 24 }
32 readme.md
Source Rendered
@@ -54,18 +54,20 @@ http://docs.jquery.com/QUnit
54 54
55 55 var testrunner = require( "qunit" );
56 56
57   - // set it to true if you want to report only errors
58   - testrunner.options.errorsOnly = false;
  57 + Defaults:
  58 +
  59 + {
  60 + errorsOnly: false, // set it to true if you want to report only errors
  61 + errorStack: true, // set it to false if you want to get error stack in report
  62 + summary: true, // print a summary about all tested stuff after finish
  63 + coverage: true, // display coverage
  64 + paths: null // add paths to require of test environment
  65 + }
59 66
60   - // set it to false if you want to get error stack in report
61   - testrunner.options.errorStack = true;
62   -
63   - // print a summary about all tested stuff after finish
64   - testrunner.options.summary = true;
65   -
66   - // add paths to require of test environment
67   - testrunner.options.paths = require.paths;
  67 + // to change any option - change it :)
68 68
  69 + testrunner.options.optionName = value;
  70 +
69 71 // one code and tests file
70 72 testrunner.run({
71 73 code: "/path/to/your/code.js",
@@ -164,10 +166,14 @@ Some tests examples
164 166
165 167 ### CLI
166 168
167   - $ node cli.js /path/to/your/code.js /path/to/your/tests.js
  169 + $ ./bin/cli --code ./code.js --tests ./tests.js
  170 +
  171 + // additionaly every option can be used
  172 + $ ./bin/cli --code ./code.js --tests ./tests.js --paths /path/for/require /path1/for/require
  173 +
  174 + $ ./bin/cli --code ./code.js --tests ./tests.js --coverage false
168 175
169   - // add require.paths
170   - $ node cli.js /path/to/your/code.js /path/to/your/tests.js /path/for/require,/path1/for/require
  176 + $ ./bin/cli --code ./code.js --tests ./tests.js --summary false
171 177
172 178 ## Run tests
173 179 $ ./bin/runtests

0 comments on commit 37f156c

Please sign in to comment.
Something went wrong with that request. Please try again.