Skip to content

Commit c1ddcae

Browse files
committed
Markdown option
1 parent 2ac2b8a commit c1ddcae

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

bin/cmd.js

+2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ var opts = minimist(process.argv.slice(2), {
66
alias: {
77
ansi: 'a',
88
progress: 'p',
9+
markdown: 'm'
910
},
1011
default: {
1112
ansi: true,
1213
progress: true,
14+
markdown: false
1315
},
1416
})
1517

example/run-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ var exec = require('child_process').exec
33
var tapeCmd = require.resolve('../node_modules/task-tape/bin/task-tape')
44
var tapCmd = require.resolve('../bin/cmd')
55
var tests = require.resolve('./test')
6-
var extra = '--no-ansi --no-progress'
6+
var extra = '--no-ansi --no-progress --markdown'
77

88
exec([tapeCmd, tests, '|', tapCmd, extra].join(' ')).stdout.pipe(process.stdout)

lib/summary.js

+28-14
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ module.exports = function (opts) {
1010
opts = opts || {}
1111
opts.ansi = typeof opts.ansi !== 'undefined' ? opts.ansi : true
1212
opts.progress = typeof opts.progress !== 'undefined' ? opts.progress : true
13+
opts.markdown = typeof opts.markdown !== 'undefined' ? opts.markdown : false
1314

1415
var format = opts.ansi ? ansi : noAnsi
16+
var splitter = opts.markdown ? mdSplitter : barSplitter
17+
18+
var INDENT = opts.markdown ? repeat(' ', 4) : ''
19+
var LIST = opts.markdown ? '- ' : ''
1520

1621
var summary = summarize()
1722
var output = summary.output
@@ -24,23 +29,23 @@ module.exports = function (opts) {
2429

2530
summary.on('test.end', function (test) {
2631
if (test.fail) {
27-
output.push(format.cha.red.eraseLine.escape(symbols.cross + ' ' + test.title))
32+
output.push(format.cha.red.eraseLine.escape(INDENT + symbols.cross + ' ' + test.title))
2833
} else {
29-
output.push(format.cha.green.eraseLine.escape(symbols.tick + ' ' + test.title))
34+
output.push(format.cha.green.eraseLine.escape(INDENT + symbols.tick + ' ' + test.title))
3035
}
3136
})
3237

3338
if (opts.progress) {
3439
summary.on('test.start', function (test) {
35-
output.push(LF + format.cha.eraseLine.escape('# ' + test.title))
40+
output.push(LF + format.cha.eraseLine.escape(INDENT + '# ' + test.title))
3641
})
3742

3843
summary.on('test.pass', function (test) {
39-
output.push(format.cha.eraseLine.escape('# ' + test.title))
44+
output.push(format.cha.eraseLine.escape(INDENT + '# ' + test.title))
4045
})
4146

4247
summary.on('test.fail', function (test) {
43-
output.push(format.cha.eraseLine.escape('# ' + test.title))
48+
output.push(format.cha.eraseLine.escape(INDENT + '# ' + test.title))
4449
})
4550
}
4651

@@ -69,17 +74,17 @@ module.exports = function (opts) {
6974
function formatSummary(res) {
7075
var output = [LF]
7176
output.push(splitter(' Summary '))
72-
output.push(format.cyan.escape('duration: ' + prettyMs(res.duration)))
73-
output.push(format.cyan.escape('assertions: ' + res.assertions))
77+
output.push(format.cyan.escape(LIST + 'duration: ' + prettyMs(res.duration)))
78+
output.push(format.cyan.escape(LIST + 'assertions: ' + res.assertions))
7479
if (res.pass) {
75-
output.push(format.green.escape('pass: ' + res.pass))
80+
output.push(format.green.escape(LIST + 'pass: ' + res.pass))
7681
} else {
77-
output.push(format.cyan.escape('pass: ' + res.pass))
82+
output.push(format.cyan.escape(LIST + 'pass: ' + res.pass))
7883
}
7984
if (res.fail) {
80-
output.push(format.red.escape('fail: ' + res.fail))
85+
output.push(format.red.escape(LIST + 'fail: ' + res.fail))
8186
} else {
82-
output.push(format.cyan.escape('fail: ' + res.fail))
87+
output.push(format.cyan.escape(LIST + 'fail: ' + res.fail))
8388
}
8489
return output.join(LF)
8590
}
@@ -93,7 +98,7 @@ module.exports = function (opts) {
9398
return output.join(LF)
9499
}
95100

96-
function splitter(s) {
101+
function barSplitter(s) {
97102
var len = s && s.length || 0
98103
var max = 80
99104
var left = max - len >> 1
@@ -102,6 +107,13 @@ module.exports = function (opts) {
102107
)
103108
}
104109

110+
function mdSplitter(s, left) {
111+
left = arguments.length > 1 ? left : 1
112+
return format.yellow.escape(
113+
repeat('#', left) + (s || '') + LF
114+
)
115+
}
116+
105117
function repeat(str, n) {
106118
if (str.repeat) {
107119
return str.repeat(n)
@@ -116,7 +128,7 @@ module.exports = function (opts) {
116128
Object.keys(fail).map(function (name) {
117129
var res = [format.cyan.underline.escape('# ' + name)]
118130
fail[name].forEach(function (assertion) {
119-
res.push(format.red.escape(' ' + symbols.cross + ' ' + assertion.name))
131+
res.push(format.red.escape(INDENT + ' ' + symbols.cross + ' ' + assertion.name))
120132
res.push(prettifyError(assertion))
121133
})
122134
return res.join(LF)
@@ -128,7 +140,9 @@ module.exports = function (opts) {
128140

129141
function prettifyError(assertion) {
130142
var rawError = assertion.error.raw
131-
var ret = rawError.split(LF)
143+
var ret = rawError.split(LF).map(function (s) {
144+
return INDENT + s
145+
})
132146
var stack = assertion.error.stack
133147
if (stack) {
134148
stack = stack.split(LF)

0 commit comments

Comments
 (0)