Skip to content

Commit

Permalink
show extra lines of output after failed assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Dec 26, 2013
1 parent 9f28030 commit ed4227a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 11 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = function (opts) {
if (!opts) opts = {};
var tap = parser();
var out = through2();
var test;
var test, lastAssert;

var replaceLine = (function () {
var prevWidth = 0;
Expand Down Expand Up @@ -56,14 +56,22 @@ module.exports = function (opts) {
test.assertions.push(res);
});

tap.on('extra', function (extra) {
var last = test.assertions[test.assertions.length-1];
if (last && !last.ok) {
out.push(extra.split('\n').map(function (line) {
return ' ' + line;
}).join('\n') + '\n');
}
});

tap.on('results', function (res) {
if (!test.ok || /^fail\s+\d+$/.test(test.name)) {
out.push(updateName(test.offset + 1, '⨯ ' + test.name, 31));
}
else {
out.push(updateName(test.offset + 1, '✓ ' + test.name, 32));
}
out.push('\x1b[1G');
out.push(null);

dup.emit('results', res);
Expand All @@ -84,6 +92,6 @@ function updateName (y, str, c) {
+ '\x1b[1m\x1b[' + c + 'm'
+ str
+ '\x1b[0m'
+ '\x1b[' + y + 'B'
+ '\x1b[' + y + 'B\x1b[1G'
;
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
},
"dependencies": {
"through2": "~0.2.3",
"tap-parser": "~0.3.0",
"tap-parser": "~0.4.0",
"duplexer": "~0.1.1",
"strip-ansi": "~0.1.1"
"strip-ansi": "~0.1.1",
"sprintf": "~0.1.3"
},
"devDependencies": {
"tape": "~2.3.2"
Expand Down

0 comments on commit ed4227a

Please sign in to comment.