From b86b7da64a1e15862a2bce9228fbbee89c76b117 Mon Sep 17 00:00:00 2001 From: James Halliday Date: Thu, 26 Dec 2013 07:17:54 -0800 Subject: [PATCH] factored out name updating --- index.js | 44 ++++++++++++++++++++++++-------------------- package.json | 3 ++- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/index.js b/index.js index cb82939..3abbbe0 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ var through2 = require('through2'); var duplexer = require('duplexer'); var parser = require('tap-parser'); var sprintf = require('sprintf'); +var strip = require('strip-ansi'); module.exports = function (opts) { if (!opts) opts = {}; @@ -13,24 +14,19 @@ module.exports = function (opts) { var prevWidth = 0; return function (str) { if (opts.width) str = str.slice(0, opts.width); - var n = prevWidth - str.length; + var len = strip(str).length; + var n = prevWidth - len; if (n < 0) n = 0; var s = str + Array(n + 1).join(' '); - prevWidth = str.length; + prevWidth = len; return '\r' + s; }; })(); tap.on('comment', function (comment) { if (test && test.ok) { - var y = test.offset + 1; - out.push( - '\r\x1b[' + y + 'A' - + '\x1b[1m\x1b[32m' - + '✓ ' + test.name - + '\x1b[0m' - + '\x1b[' + y + 'B' - ); + var s = updateName(test.offset + 1, '✓ ' + test.name, 32); + out.push('\r' + s); } test = { @@ -44,19 +40,15 @@ module.exports = function (opts) { tap.on('assert', function (res) { var ok = res.ok ? 'ok' : 'not ok'; - var fmt = '%4d. %s %s'; - var str = replaceLine(sprintf(fmt, res.number, ok, res.name)); + var c = res.ok ? 32 : 31; + var fmt = ' %s \x1b[1m\x1b[' + c + 'm%d\x1b[0m %s'; + var str = replaceLine(sprintf(fmt, ok, res.number, res.name)); if (!res.ok) { var y = (++ test.offset) + 1; str += '\n'; if (test.ok) { - str += '\x1b[' + y + 'A' - + '\x1b[1m\x1b[31m' - + '⨯ ' + test.name - + '\x1b[0m' - + '\x1b[' + y + 'B' - ; + str += updateName(y, '⨯ ' + test.name, 31) } test.ok = false; } @@ -64,8 +56,11 @@ module.exports = function (opts) { test.assertions.push(res); }); - tap.on('result', function (res) { - // + tap.on('results', function (res) { + if (/^fail\s/.test(test.name)) { + + console.log(test.name); + } }); return duplexer(tap, out); @@ -74,3 +69,12 @@ module.exports = function (opts) { out.push('\r'); } }; + +function updateName (y, str, c) { + return '\x1b[' + y + 'A' + + '\x1b[1m\x1b[' + c + 'm' + + str + + '\x1b[0m' + + '\x1b[' + y + 'B' + ; +} diff --git a/package.json b/package.json index 933b0ba..ad6de9c 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "dependencies": { "through2": "~0.2.3", "tap-parser": "~0.3.0", - "duplexer": "~0.1.1" + "duplexer": "~0.1.1", + "strip-ansi": "~0.1.1" }, "devDependencies": { "tape": "~2.3.2"