Skip to content

Commit 6625e9a

Browse files
author
Michael Hayes
committed
improve yaml formatting of diagnostic information
1 parent 38a8a9d commit 6625e9a

File tree

4 files changed

+47
-45
lines changed

4 files changed

+47
-45
lines changed

lib/results.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ var through = require('through');
44
var resumer = require('resumer');
55
var inspect = require('object-inspect');
66
var hasOwn = Object.prototype.hasOwnProperty;
7+
var regexpTest = RegExp.prototype.test
8+
var yamlIndicators = /\:|\-|\?/;
79
var nextTick = typeof setImmediate !== 'undefined'
810
? setImmediate
911
: process.nextTick
@@ -145,10 +147,10 @@ function encodeResult (res, count) {
145147
if (has(res, 'expected') || has(res, 'actual')) {
146148
var ex = inspect(res.expected);
147149
var ac = inspect(res.actual);
148-
149-
if (Math.max(ex.length, ac.length) > 65) {
150-
output += inner + 'expected:\n' + inner + ' ' + ex + '\n';
151-
output += inner + 'actual:\n' + inner + ' ' + ac + '\n';
150+
151+
if (Math.max(ex.length, ac.length) > 65 || invalidYaml(ex) || invalidYaml(ac)) {
152+
output += inner + 'expected: |-\n' + inner + ' ' + ex + '\n';
153+
output += inner + 'actual: |-\n' + inner + ' ' + ac + '\n';
152154
}
153155
else {
154156
output += inner + 'expected: ' + ex + '\n';
@@ -160,10 +162,9 @@ function encodeResult (res, count) {
160162
}
161163
if (res.operator === 'error' && res.actual && res.actual.stack) {
162164
var lines = String(res.actual.stack).split('\n');
163-
output += inner + 'stack:\n';
164-
output += inner + ' ' + lines[0] + '\n';
165-
for (var i = 1; i < lines.length; i++) {
166-
output += inner + lines[i] + '\n';
165+
output += inner + 'stack: |-\n';
166+
for (var i = 0; i < lines.length; i++) {
167+
output += inner + ' ' + lines[i] + '\n';
167168
}
168169
}
169170

@@ -188,3 +189,7 @@ function getNextTest (results) {
188189
function has (obj, prop) {
189190
return hasOwn.call(obj, prop);
190191
}
192+
193+
function invalidYaml (str) {
194+
return regexpTest.call(yamlIndicators, str);
195+
}

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
"through": "~2.3.4"
1919
},
2020
"devDependencies": {
21-
"tap": "~0.7.1",
21+
"concat-stream": "~1.4.1",
2222
"falafel": "~1.0.1",
23-
"concat-stream": "~1.4.1"
23+
"js-yaml": "^3.3.1",
24+
"tap": "~0.7.1",
25+
"tap-parser": "^1.1.6"
2426
},
2527
"scripts": {
2628
"test": "tap test/*.js"

test/circular-things.js

+26-33
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,36 @@
11
var tape = require('../');
22
var tap = require('tap');
3+
var concat = require('concat-stream');
34

45
tap.test('circular test', function (assert) {
56
var test = tape.createHarness({ exit : false });
6-
var tc = tap.createConsumer();
7+
assert.plan(1);
78

8-
var rows = [];
9-
tc.on('data', function (r) { rows.push(r) });
10-
tc.on('end', function () {
11-
// console.log("rs", rows)
12-
13-
// console.log("deepEqual?")
14-
15-
assert.same(rows, [
16-
"TAP version 13"
17-
, "circular"
18-
, { id: 1
19-
, ok: false
20-
, name: " should be equal"
21-
, operator: "equal"
22-
, expected: "{}"
23-
, actual: '{ circular: [Circular] }'
24-
}
25-
, "tests 1"
26-
, "pass 0"
27-
, "fail 1"
28-
])
29-
assert.end()
30-
})
31-
32-
// tt.equal(10, 10)
33-
// tt.end()
34-
35-
test.createStream().pipe(tc);
9+
test.createStream().pipe(concat(function (body) {
10+
assert.equal(
11+
body.toString('utf8'),
12+
'TAP version 13\n'
13+
+ '# circular\n'
14+
+ 'not ok 1 should be equal\n'
15+
+ ' ---\n'
16+
+ ' operator: equal\n'
17+
+ ' expected: |-\n'
18+
+ ' {}\n'
19+
+ ' actual: |-\n'
20+
+ ' { circular: [Circular] }\n'
21+
+ ' ...\n'
22+
+ '\n'
23+
+ '1..1\n'
24+
+ '# tests 1\n'
25+
+ '# pass 0\n'
26+
+ '# fail 1\n'
27+
);
28+
}));
3629

3730
test("circular", function (t) {
38-
t.plan(1)
39-
var circular = {}
40-
circular.circular = circular
41-
t.equal(circular, {})
31+
t.plan(1);
32+
var circular = {};
33+
circular.circular = circular;
34+
t.equal(circular, {});
4235
})
4336
})

test/undef.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ tap.test('array test', function (tt) {
1414
+ 'not ok 1 should be equivalent\n'
1515
+ ' ---\n'
1616
+ ' operator: deepEqual\n'
17-
+ ' expected: { beep: undefined }\n'
18-
+ ' actual: {}\n'
17+
+ ' expected: |-\n'
18+
+ ' { beep: undefined }\n'
19+
+ ' actual: |-\n'
20+
+ ' {}\n'
1921
+ ' ...\n'
2022
+ '\n'
2123
+ '1..1\n'

0 commit comments

Comments
 (0)