Permalink
Browse files

merge to latest

  • Loading branch information...
2 parents 27e27d1 + 485698d commit 564d18355e12d5184de181715b2c285cc46ba3b7 @hpychan committed Sep 7, 2011
View
@@ -37,3 +37,10 @@ documentation
Head over to <http://vowsjs.org>
+authors
+-------
+
+Alexis Sellier <<alexis@cloudhead.io>>, Charlie Robbins,
+
+*...and many others*
+
View
149 bin/vows
@@ -39,7 +39,7 @@ var vows = require('../lib/vows');
var cutils = require('../lib/vows/console');
var stylize = require('../lib/vows/console').stylize;
var _reporter = require('../lib/vows/reporters/dot-matrix'), reporter = {
- name: _reporter.name,
+ name: _reporter.name
};
var _coverage;
@@ -50,6 +50,7 @@ var help = [
" -v, --verbose Enable verbose output",
" -w, --watch Watch mode",
" -s, --silent Don't report",
+ " -i, --isolate Run each test in it's own vows process",
" -m PATTERN Only run tests matching the PATTERN string",
" -r PATTERN Only run tests matching the PATTERN regexp",
" --json Use JSON reporter",
@@ -58,6 +59,7 @@ var help = [
" --xunit Use xUnit reporter",
" --cover-plain Print plain coverage map if detected",
" --cover-html Write coverage map to \"coverage.html\"",
+ " --cover-json Write unified coverage map to \"coverage.json\"",
//" --no-color Don't use terminal colors",
" --version Show version",
" -h, --help You're staring at it"
@@ -67,7 +69,8 @@ var options = {
reporter: reporter,
matcher: /.*/,
watch: false,
- coverage: false
+ coverage: false,
+ isolate: false
};
var files = [];
@@ -103,15 +106,13 @@ 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 '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;
@@ -136,6 +137,10 @@ while (arg = argv.shift()) {
options.coverage = true;
_coverage = require('../lib/vows/coverage/report-html');
break;
+ case 'cover-json':
+ options.coverage = true;
+ _coverage = require('../lib/vows/coverage/report-json');
+ break;
case 'verbose':
case 'v':
options.verbose = true;
@@ -144,6 +149,13 @@ while (arg = argv.shift()) {
case 'w':
options.watch = true;
break;
+ case 'supress-stdout':
+ options.supressStdout = true;
+ break;
+ case 'isolate':
+ case 'i':
+ options.isolate = true;
+ break;
case 'no-color':
options.nocolor = true;
break;
@@ -163,6 +175,11 @@ while (arg = argv.shift()) {
}
}
+if (options.supressStdout) {
+ _reporter.setStream && _reporter.setStream(process.stdout);
+ process.stdout = fs.createWriteStream('/dev/null');
+}
+
if (options.watch) {
options.reporter = reporter = require('../lib/vows/reporters/watch');
}
@@ -205,34 +222,48 @@ if (! options.watch) {
_reporter.report(data, filename);
break;
case 'end':
- (options.verbose || _reporter.name === 'json') && _reporter.report(data);
+ (options.verbose || _reporter.name === 'json') &&
+ _reporter.report(data);
break;
case 'finish':
- options.verbose ? _reporter.print('\n') : _reporter.print(' ');
+ options.verbose ?
+ _reporter.print('\n')
+ :
+ _reporter.print(' ');
break;
}
};
reporter.reset = function () { _reporter.reset && _reporter.reset() };
reporter.print = _reporter.print;
files = args.map(function (a) {
- return path.join(process.cwd(), a.replace(fileExt, ''));
+ return (!a.match(/^\//))
+ ? path.join(process.cwd(), a.replace(fileExt, ''))
+ : a.replace(fileExt, '');
});
var allTests = function() {
- runSuites(importSuites(files), function (results) {
- var status = results.errored ? 2 : (results.broken ? 1 : 0);
+ 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'));
- }
- });
+ !options.verbose && _reporter.print('\n');
+ msg('runner', 'finish');
+ _reporter.report(['finish', results], {
+ write: function (str) {
+ util.print(str.replace(/^\n\n/, '\n'));
+ }
+ });
+ try {
+ if (options.coverage === true && _$jscoverage !== undefined) {
+ _coverage.report(_$jscoverage);
+ }
+ } catch (err) {
+ // ignore the undefined jscoverage
+ }
+ if (process.stdout.write('')) { // Check if stdout is drained
if (options.coverage === true && _$jscoverage !== undefined) {
- _coverage.report(_$jscoverage);
+ _coverage.report(_$jscoverage);
}
if (process.stdout.write('')) { // Check if stdout is drained
process.exit(status);
@@ -245,14 +276,14 @@ if (! options.watch) {
};
- 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 {
+ 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 {
//
@@ -402,10 +433,62 @@ function runSuites(suites, callback) {
function importSuites(files) {
msg(options.watcher ? 'watcher' : 'runner', 'loading', files);
- return files.reduce(function (suites, f) {
+ var spawn = require('child_process').spawn;
+
+ function cwdname(f) {
+ return f.replace(process.cwd() + '/', '') + '.js';
+ }
+
+ function wrapSpawn(f) {
+ f = cwdname(f);
+ return function (options, callback) {
+ var args = [process.argv[1], '--json', '--supress-stdout', f],
+ p = spawn(process.argv[0], args),
+ result;
+
+ p.on('exit', function (code) {
+ callback(
+ !result ?
+ {errored: 1, total: 1}
+ :
+ result
+ );
+ });
+
+ var buffer = [];
+ p.stdout.on('data', function (data) {
+ data = data.toString().split(/\n/g);
+ if (data.length == 1) {
+ buffer.push(data[0]);
+ } else {
+ data[0] = buffer.concat(data[0]).join('');
+ buffer = [data.pop()];
+
+ data.forEach(function (data) {
+ if (data) {
+ data = JSON.parse(data);
+ if (data && data[0] === 'finish') {
+ result = data[1];
+ } else {
+ reporter.report(data);
+ }
+ }
+ });
+ }
+ });
+
+ p.stderr.pipe(process.stderr);
+ }
+ }
+
+ return files.reduce(options.isolate ? function (suites, f) {
+ return suites.concat({
+ run: wrapSpawn(f)
+ });
+ } : function (suites, f) {
var obj = require(f);
return suites.concat(Object.keys(obj).map(function (s) {
- obj[s]._filename = f.replace(process.cwd() + '/', '') + '.js';
+ obj[s]._filename = cwdname(f);
return obj[s];
}));
}, [])
View
@@ -104,6 +104,11 @@ assert.isEmpty = function (actual, message) {
assert.fail(actual, 0, message || "expected {actual} to be empty", "length", assert.isEmpty);
}
};
+assert.isNotEmpty = function (actual, message) {
+ if ((isObject(actual) && Object.keys(actual).length === 0) || actual.length === 0) {
+ assert.fail(actual, 0, message || "expected {actual} to be not empty", "length", assert.isNotEmpty);
+ }
+};
assert.length = function (actual, expected, message) {
if (actual.length !== expected) {
@@ -152,6 +157,11 @@ assert.isUndefined = function (actual, message) {
assert.fail(actual, undefined, message || "expected {actual} to be {expected}", "===", assert.isUndefined);
}
};
+assert.isDefined = function (actual, message) {
+ if(actual === undefined) {
+ assert.fail(actual, 0, message || "expected {actual} to be defined", "===", assert.isDefined);
+ }
+};
assert.isString = function (actual, message) {
assertTypeOf(actual, 'string', message || "expected {actual} to be a String", assert.isString);
};
View
@@ -73,7 +73,7 @@ function addVow(vow) {
}).on("error", function (err) {
if (vow.callback.length >= 2 || !batch.suite.options.error) {
- runTest([err], this.ctx);
+ runTest(arguments, this.ctx);
} else {
output('errored', { type: 'promise', error: err.stack || err.message || JSON.stringify(err) });
}
View
@@ -32,12 +32,18 @@ var $ = this.$ = function (str) {
this.puts = function (options) {
var stylize = exports.stylize;
+ options.stream || (options.stream = process.stdout);
+ options.tail = options.tail || '';
+
return function (args) {
- args = Array.prototype.slice.call(arguments).map(function (a) {
- return a.replace(/`([^`]+)`/g, function (_, capture) { return stylize(capture, 'italic') })
- .replace(/\*([^*]+)\*/g, function (_, capture) { return stylize(capture, 'bold') });
- });
- return options.stream.write(args.join('\n') + '\n');
+ args = Array.prototype.slice.call(arguments);
+ if (!options.raw) {
+ args = args.map(function (a) {
+ return a.replace(/`([^`]+)`/g, function (_, capture) { return stylize(capture, 'italic') })
+ .replace(/\*([^*]+)\*/g, function (_, capture) { return stylize(capture, 'bold') });
+ });
+ }
+ return options.stream.write(args.join('\n') + options.tail);
};
};
@@ -73,7 +79,7 @@ this.result = function (event) {
time = ' (' + event.time.toFixed(3) + 's)';
time = this.stylize(time, 'grey');
}
- buffer.push(header + result + time);
+ buffer.push(header + result + time + '\n');
return buffer;
};
@@ -91,3 +97,35 @@ this.error = function (obj) {
return string;
};
+
+this.contextText = function (event) {
+ return ' ' + event;
+};
+
+this.vowText = function (event) {
+ var buffer = [];
+
+ buffer.push(' ' + {
+ honored: '',
+ broken: '',
+ errored: '',
+ pending: ' - '
+ }[event.status] + this.stylize(event.title, ({
+ honored: 'green',
+ broken: 'yellow',
+ errored: 'red',
+ pending: 'cyan'
+ })[event.status]));
+
+ if (event.status === 'broken') {
+ buffer.push(' » ' + event.exception);
+ } else if (event.status === 'errored') {
+ if (event.exception.type === 'promise') {
+ buffer.push(' » ' + this.stylize("An unexpected error was caught: " +
+ this.stylize(event.exception.error, 'bold'), 'red'));
+ } else {
+ buffer.push(' ' + this.stylize(event.exception, 'red'));
+ }
+ }
+ return buffer.join('\n');
+};
View
@@ -28,7 +28,7 @@ this.Context = function (vow, ctx, env) {
if (typeof(e) === 'boolean' && args.length === 0) {
that.emitter.emit.call(that.emitter, 'success', e);
} else {
- if (e) { that.emitter.emit.call(that.emitter, 'error', e) }
+ if (e) { that.emitter.emit.apply(that.emitter, ['error', e].concat(args)) }
else { that.emitter.emit.apply(that.emitter, ['success'].concat(args)) }
}
};
Oops, something went wrong.

0 comments on commit 564d183

Please sign in to comment.