Permalink
Browse files

add new logging option for currently testing file, update docs

  • Loading branch information...
1 parent 474ed8e commit d44f71834835be83130d6bd2955519237392a941 @kof kof committed Mar 26, 2012
Showing with 60 additions and 74 deletions.
  1. +5 −20 bin/cli.js
  2. +5 −18 lib/log.js
  3. +22 −5 lib/testrunner.js
  4. +1 −1 package.json
  5. +21 −24 readme.md
  6. +6 −6 test/testrunner.js
View
@@ -18,12 +18,8 @@ help = ''
+ '\n -c, --code path to code you want to test'
+ '\n -t, --tests path to tests (space separated)'
+ '\n -d, --deps dependency paths - files required before code (space separated)'
- + '\n -o, --errors-only report only errors'
- + '\n -e, --error-stack display error stack'
- + '\n -s, --summary display summary report'
+ + '\n -l, --log logging options, json have to be used'
+ '\n --cov create tests coverage report'
- + '\n -p, --paths, add paths to require.paths array'
- + '\n --tmp change temp dir, which is used for jscoverage tool'
+ '\n -h, --help show this help'
+ '\n -v, --version show module version'
+ '\n';
@@ -72,22 +68,14 @@ for (var key in args) {
case '-d':
case '--deps':
o.deps = args[key];
- if (!Array.isArray (o.deps)) {
+ if (!Array.isArray(o.deps)) {
o.deps = [o.deps];
}
o.deps = o.deps.map(parsePath);
break;
- case '-o':
- case '--errors-only':
- o.errorsOnly = args[key];
- break;
- case '-e':
- case '--error-stack':
- o.errorStack = args[key];
- break;
- case '-s':
- case '--summary':
- o.summary = args[key];
+ case '-l':
+ case '--log':
+ eval('o.log = ' + args[key]);
break;
case '--cov':
o.coverage = args[key];
@@ -96,9 +84,6 @@ for (var key in args) {
case '--paths':
o.paths = args[key];
break;
- case '--tmp':
- o.coverageTmpDir = args[key];
- break;
case '-v':
case '--version':
util.print(
View
@@ -69,7 +69,7 @@ exports.reset = function() {
};
};
-var print = {};
+var print = exports.print = {};
print.assertions = function() {
var table,
@@ -99,7 +99,7 @@ print.assertions = function() {
table.push([module, test, data.message, data.result ? 'ok' : 'fail']);
});
- log('Assertions:\n' + table.toString());
+ log('\nAssertions:\n' + table.toString());
};
print.errors = function() {
@@ -143,7 +143,7 @@ print.tests = function() {
table.push([module, data.name, data.failed, data.passed, data.total]);
});
- log('\Tests:\n' + table.toString());
+ log('\nTests:\n' + table.toString());
};
print.summary = function() {
@@ -165,7 +165,7 @@ print.summary = function() {
table.push([code, data.failed, data.passed, data.total, data.runtime]);
});
- log('\Summary:\n' + table.toString());
+ log('\nSummary:\n' + table.toString());
};
print.globalSummary = function() {
@@ -180,18 +180,5 @@ print.globalSummary = function() {
table.push([data.files, data.tests, data.assertions, data.failed,
data.passed, data.runtime]);
- log('\Global summary:\n' + table.toString());
-};
-
-/**
- * Print stats table to the stdout
- * @param {String} name of the table.
- * @api public
- */
-exports.print = function(name) {
- if (print[name]) {
- print[name]();
- } else {
- throw new Error('bad stats name: ' + name );
- }
+ log('\nGlobal summary:\n' + table.toString());
};
View
@@ -3,7 +3,8 @@ var fs = require('fs'),
coverage = require('./coverage'),
cp = require('child_process'),
_ = require('underscore'),
- log = exports.log = require('./log');
+ log = exports.log = require('./log'),
+ util = require('util');
var options;
@@ -27,6 +28,8 @@ options = exports.options = {
// log global summary (all files)
globalSummary: true,
+ // log currently testing code file
+ testing: true
},
// run test coverage tool
@@ -61,12 +64,17 @@ function runOne(opts, callback) {
} else if (msg.event === 'done') {
msg.data.code = opts.code.path;
log.summary(msg.data);
-
+ if (opts.log.testing) {
+ util.print('done');
+ }
callback(msg.data);
-
child.kill();
}
});
+
+ if (opts.log.testing) {
+ util.print('\nTesting ', opts.code.path + ' ... ');
+ }
}
/**
@@ -129,8 +137,8 @@ exports.run = function(files, callback) {
if (filesCount >= files.length) {
_.each(opts.log, function(val, name) {
- if (val) {
- log.print(name);
+ if (val && log.print[name]) {
+ log.print[name]();
}
})
@@ -147,3 +155,12 @@ exports.run = function(files, callback) {
}
});
};
+
+
+/**
+ * Set options
+ * @param {Object}
+ */
+exports.setup = function(opts) {
+ _.extend(options, opts);
+};
View
@@ -1,7 +1,7 @@
{
"name": "qunit",
"description": "A port of QUnit unit testing framework to nodejs",
- "version": "0.4.0",
+ "version": "0.5.0",
"author": "Oleg Slobodskoi <oleg008@gmail.com>",
"contributors": [
{"name": "Jonathan Buchanan"},
View
@@ -95,7 +95,7 @@ By default, code and dependencies are added to the global scope. To specify
requiring them into a namespace object, prefix the path or module name with the
variable name to be used for the namespace object, followed by a colon:
- $ qunit -c code:./code.js -d utils:utilmodule -r ./time.js
+ $ qunit -c code:./code.js -d utils:utilmodule -t ./time.js
### via api
@@ -105,40 +105,37 @@ variable name to be used for the namespace object, followed by a colon:
{
- // logging options
- log: {
+ // log assertions overview
+ assertions: true,
- // log assertions overview
- assertions: true,
+ // log expected and actual values for failed tests
+ errors: true,
- // log expected and actual values for failed tests
- errors: true,
+ // log tests overview
+ tests: true,
- // log tests overview
- tests: true,
+ // log summary
+ summary: true,
- // log summary
- summary: true,
+ // log global summary (all files)
+ globalSummary: true,
- // log global summary (all files)
- globalSummary: true,
-
- },
-
- // run test coverage tool
- coverage: false,
-
- // define dependencies, which are required then before code
- deps: null,
-
- // define namespace your code will be attached to on global['your namespace']
- namespace: null
+ // log currently testing code file
+ testing: true
}
// change any option for all tests globally
testrunner.options.optionName = value;
+ // or use setup function
+ testrunner.setup({
+ log: {
+ summary: true
+ }
+ });
+
+
// one code and tests file
testrunner.run({
code: "/path/to/your/code.js",
View
@@ -8,7 +8,7 @@ var tr = require('../lib/testrunner'),
var fixtures = __dirname + '/fixtures',
chain = chainer();
-_.extend(tr.options, {
+_.extend(tr.options.log, {
assertions: false,
tests: false,
summary: false,
@@ -27,7 +27,7 @@ chain.add('base testrunner', function() {
tr.run({
code: fixtures + '/testrunner-code.js',
tests: fixtures + '/testrunner-tests.js',
- }, function(res) {
+ }, function(err, res) {
var stat = {
files: 1,
tests: 2,
@@ -45,7 +45,7 @@ chain.add('attach code to global', function() {
tr.run({
code: fixtures + '/child-code-global.js',
tests: fixtures + '/child-tests-global.js',
- }, function(res) {
+ }, function(err, res) {
var stat = {
files: 1,
tests: 1,
@@ -67,7 +67,7 @@ chain.add('attach code to a namespace', function() {
namespace: 'testns'
},
tests: fixtures + '/child-tests-namespace.js',
- }, function(res) {
+ }, function(err, res) {
var stat = {
files: 1,
tests: 1,
@@ -86,7 +86,7 @@ chain.add('async testing logs', function() {
tr.run({
code: fixtures + '/async-code.js',
tests: fixtures + '/async-test.js',
- }, function(res) {
+ }, function(err, res) {
var stat = {
files: 1,
tests: 2,
@@ -102,7 +102,7 @@ chain.add('async testing logs', function() {
});
chain.add(function() {
- console.log('All tests done');
+ console.log('\nAll tests done');
});
chain.start();

0 comments on commit d44f718

Please sign in to comment.