Permalink
Browse files

Add include library and coverage report feature

  • Loading branch information...
1 parent 76565ef commit 27e27d129538af5beaf5d9d9d99d70cb96cfbc7a @hpychan committed Jul 28, 2011
Showing with 46 additions and 22 deletions.
  1. +46 −22 bin/vows
View
@@ -3,6 +3,7 @@
var path = require('path'),
fs = require('fs'),
util = require('util'),
+ childProcess = require('child_process'),
events = require('events');
//
@@ -102,6 +103,15 @@ while (arg = argv.shift()) {
options[arg] = true;
} else {
switch (arg) {
+ case 'i':
+ case 'I':
+ case 'include':
+ if (arg = argv.shift()) {
+ require.paths.unshift(arg);
+ } else {
+ throw new Error('--include requires a path');
+ }
+ break;
case 'json':
_reporter = require('../lib/vows/reporters/json');
break;
@@ -208,28 +218,42 @@ if (! options.watch) {
files = args.map(function (a) {
return path.join(process.cwd(), a.replace(fileExt, ''));
});
-
- runSuites(importSuites(files), function (results) {
- var status = results.errored ? 2 : (results.broken ? 1 : 0);
-
- !options.verbose && _reporter.print('\n');
- msg('runner', 'finish');
- _reporter.report(['finish', results], {
- write: function (str) {
- util.print(str.replace(/^\n\n/, '\n'));
- }
- });
- if (options.coverage === true && _$jscoverage !== undefined) {
- _coverage.report(_$jscoverage);
- }
- if (process.stdout.write('')) { // Check if stdout is drained
- process.exit(status);
- } else {
- process.stdout.on('drain', function () {
- process.exit(status);
- });
- }
- });
+
+ var allTests = function() {
+
+ runSuites(importSuites(files), function (results) {
+ var status = results.errored ? 2 : (results.broken ? 1 : 0);
+
+ !options.verbose && _reporter.print('\n');
+ msg('runner', 'finish');
+ _reporter.report(['finish', results], {
+ write: function (str) {
+ util.print(str.replace(/^\n\n/, '\n'));
+ }
+ });
+ if (options.coverage === true && _$jscoverage !== undefined) {
+ _coverage.report(_$jscoverage);
+ }
+ if (process.stdout.write('')) { // Check if stdout is drained
+ process.exit(status);
+ } else {
+ process.stdout.on('drain', function () {
+ process.exit(status);
+ });
+ }
+ });
+ };
+
+
+ if (options.coverage === true ) {
+ childProcess.exec('rm -fr lib-cov && jscoverage lib lib-cov', function(err){
+ if (err) throw err;
+ require.paths.unshift('lib-cov');
+ allTests();
+ })
+ } else {
+ allTests();
+ }
} else {
//
// Watch mode

3 comments on commit 27e27d1

Sweet, this completely obviates my testrunner.js that dif this in lieu of it!

Owner

hpychan replied Jul 28, 2011

is it a good thing??

Yes :)

Please sign in to comment.