Skip to content

Commit

Permalink
hacks for mocha tap formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Dec 26, 2013
1 parent 085e600 commit 1e629ea
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
8 changes: 6 additions & 2 deletions bin/cmd.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
#!/usr/bin/env node
var faucet = require('../');
var minimist = require('minimist');
var defined = require('defined');
var tapeCmd = require.resolve('tape/bin/tape');

var spawn = require('child_process').spawn;
var fs = require('fs');
var path = require('path');

var argv = minimist(process.argv.slice(2));
var tap = faucet({
width: process.stdout.isTTY ? process.stdout.columns : 0
width: defined(argv.w, argv.width, process.stdout.isTTY
? process.stdout.columns - 5
: 0
)
});
process.on('exit', function (code) {
if (code === 0 && tap.exitCode !== 0) {
process.exit(tap.exitCode);
}
});

var argv = minimist(process.argv.slice(2));
if (!process.stdin.isTTY || argv._[0] === '-') {
process.stdin.pipe(tap).pipe(process.stdout);
return;
Expand Down
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ module.exports = function (opts) {
tap.on('assert', function (res) {
var ok = res.ok ? 'ok' : 'not ok';
var c = res.ok ? 32 : 31;
if (!test) {
// mocha produces TAP results this way, whatever
var s = res.name.trim();
if (opts.width && s.length > opts.width - 2) {
s = s.slice(0, opts.width - 5) + '...';
}
out.push(sprintf(
'\x1b[1m\x1b[' + c + 'm%s %s\x1b[0m\n',
res.ok ? '✓' : '⨯', s
));
return;
}

var fmt = '\r %s \x1b[1m\x1b[' + c + 'm%d\x1b[0m %s\x1b[K';
var str = sprintf(fmt, ok, res.number, res.name);

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"duplexer": "~0.1.1",
"sprintf": "~0.1.3",
"tape": "~2.3.2",
"minimist": "0.0.5"
"minimist": "0.0.5",
"defined": "0.0.0"
},
"scripts": {
"test": "tape test/*.js"
Expand Down

0 comments on commit 1e629ea

Please sign in to comment.