Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/hpychan/vows
Browse files Browse the repository at this point in the history
Conflicts:
	package.json
  • Loading branch information
Henry Chan committed Oct 17, 2011
2 parents 30c6acc + e9094fe commit 858ed58
Show file tree
Hide file tree
Showing 22 changed files with 711 additions and 108 deletions.
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -37,3 +37,10 @@ documentation

Head over to <http://vowsjs.org>

authors
-------

Alexis Sellier <<alexis@cloudhead.io>>, Charlie Robbins,

*...and many others*

157 changes: 123 additions & 34 deletions bin/vows
Expand Up @@ -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;

Expand All @@ -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",
Expand All @@ -58,6 +59,8 @@ 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\"",
" --cover-emma Write unified coverage map to \"coverage.emma\"",
//" --no-color Don't use terminal colors",
" --version Show version",
" -h, --help You're staring at it"
Expand All @@ -67,7 +70,8 @@ var options = {
reporter: reporter,
matcher: /.*/,
watch: false,
coverage: false
coverage: false,
isolate: false
};

var files = [];
Expand Down Expand Up @@ -103,15 +107,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;
Expand All @@ -136,6 +138,14 @@ 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 'cover-emma':
options.coverage = true;
_coverage = require('../lib/vows/coverage/report-emma');
break;
case 'verbose':
case 'v':
options.verbose = true;
Expand All @@ -144,6 +154,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;
Expand All @@ -163,6 +180,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');
}
Expand Down Expand Up @@ -205,34 +227,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);
Expand All @@ -241,18 +277,19 @@ if (! options.watch) {
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 {
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 {
//
Expand Down Expand Up @@ -402,10 +439,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];
}));
}, [])
Expand Down
10 changes: 10 additions & 0 deletions lib/assert/macros.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
};
Expand Down
2 changes: 1 addition & 1 deletion lib/vows.js
Expand Up @@ -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) });
}
Expand Down
50 changes: 44 additions & 6 deletions lib/vows/console.js
Expand Up @@ -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);
};
};

Expand Down Expand Up @@ -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;
};
Expand All @@ -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');
};
2 changes: 1 addition & 1 deletion lib/vows/context.js
Expand Up @@ -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)) }
}
};
Expand Down

0 comments on commit 858ed58

Please sign in to comment.