@@ -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