Skip to content

Commit

Permalink
Markdown option
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypercubed committed Jun 1, 2016
1 parent 2ac2b8a commit c1ddcae
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
2 changes: 2 additions & 0 deletions bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ var opts = minimist(process.argv.slice(2), {
alias: {
ansi: 'a',
progress: 'p',
markdown: 'm'
},
default: {
ansi: true,
progress: true,
markdown: false
},
})

Expand Down
2 changes: 1 addition & 1 deletion example/run-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ var exec = require('child_process').exec
var tapeCmd = require.resolve('../node_modules/task-tape/bin/task-tape')
var tapCmd = require.resolve('../bin/cmd')
var tests = require.resolve('./test')
var extra = '--no-ansi --no-progress'
var extra = '--no-ansi --no-progress --markdown'

exec([tapeCmd, tests, '|', tapCmd, extra].join(' ')).stdout.pipe(process.stdout)
42 changes: 28 additions & 14 deletions lib/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ module.exports = function (opts) {
opts = opts || {}
opts.ansi = typeof opts.ansi !== 'undefined' ? opts.ansi : true
opts.progress = typeof opts.progress !== 'undefined' ? opts.progress : true
opts.markdown = typeof opts.markdown !== 'undefined' ? opts.markdown : false

var format = opts.ansi ? ansi : noAnsi
var splitter = opts.markdown ? mdSplitter : barSplitter

var INDENT = opts.markdown ? repeat(' ', 4) : ''
var LIST = opts.markdown ? '- ' : ''

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

summary.on('test.end', function (test) {
if (test.fail) {
output.push(format.cha.red.eraseLine.escape(symbols.cross + ' ' + test.title))
output.push(format.cha.red.eraseLine.escape(INDENT + symbols.cross + ' ' + test.title))
} else {
output.push(format.cha.green.eraseLine.escape(symbols.tick + ' ' + test.title))
output.push(format.cha.green.eraseLine.escape(INDENT + symbols.tick + ' ' + test.title))
}
})

if (opts.progress) {
summary.on('test.start', function (test) {
output.push(LF + format.cha.eraseLine.escape('# ' + test.title))
output.push(LF + format.cha.eraseLine.escape(INDENT + '# ' + test.title))
})

summary.on('test.pass', function (test) {
output.push(format.cha.eraseLine.escape('# ' + test.title))
output.push(format.cha.eraseLine.escape(INDENT + '# ' + test.title))
})

summary.on('test.fail', function (test) {
output.push(format.cha.eraseLine.escape('# ' + test.title))
output.push(format.cha.eraseLine.escape(INDENT + '# ' + test.title))
})
}

Expand Down Expand Up @@ -69,17 +74,17 @@ module.exports = function (opts) {
function formatSummary(res) {
var output = [LF]
output.push(splitter(' Summary '))
output.push(format.cyan.escape('duration: ' + prettyMs(res.duration)))
output.push(format.cyan.escape('assertions: ' + res.assertions))
output.push(format.cyan.escape(LIST + 'duration: ' + prettyMs(res.duration)))
output.push(format.cyan.escape(LIST + 'assertions: ' + res.assertions))
if (res.pass) {
output.push(format.green.escape('pass: ' + res.pass))
output.push(format.green.escape(LIST + 'pass: ' + res.pass))
} else {
output.push(format.cyan.escape('pass: ' + res.pass))
output.push(format.cyan.escape(LIST + 'pass: ' + res.pass))
}
if (res.fail) {
output.push(format.red.escape('fail: ' + res.fail))
output.push(format.red.escape(LIST + 'fail: ' + res.fail))
} else {
output.push(format.cyan.escape('fail: ' + res.fail))
output.push(format.cyan.escape(LIST + 'fail: ' + res.fail))
}
return output.join(LF)
}
Expand All @@ -93,7 +98,7 @@ module.exports = function (opts) {
return output.join(LF)
}

function splitter(s) {
function barSplitter(s) {
var len = s && s.length || 0
var max = 80
var left = max - len >> 1
Expand All @@ -102,6 +107,13 @@ module.exports = function (opts) {
)
}

function mdSplitter(s, left) {
left = arguments.length > 1 ? left : 1
return format.yellow.escape(
repeat('#', left) + (s || '') + LF
)
}

function repeat(str, n) {
if (str.repeat) {
return str.repeat(n)
Expand All @@ -116,7 +128,7 @@ module.exports = function (opts) {
Object.keys(fail).map(function (name) {
var res = [format.cyan.underline.escape('# ' + name)]
fail[name].forEach(function (assertion) {
res.push(format.red.escape(' ' + symbols.cross + ' ' + assertion.name))
res.push(format.red.escape(INDENT + ' ' + symbols.cross + ' ' + assertion.name))
res.push(prettifyError(assertion))
})
return res.join(LF)
Expand All @@ -128,7 +140,9 @@ module.exports = function (opts) {

function prettifyError(assertion) {
var rawError = assertion.error.raw
var ret = rawError.split(LF)
var ret = rawError.split(LF).map(function (s) {
return INDENT + s
})
var stack = assertion.error.stack
if (stack) {
stack = stack.split(LF)
Expand Down

0 comments on commit c1ddcae

Please sign in to comment.