@@ -10,8 +10,13 @@ module.exports = function (opts) {
10
10
opts = opts || { }
11
11
opts . ansi = typeof opts . ansi !== 'undefined' ? opts . ansi : true
12
12
opts . progress = typeof opts . progress !== 'undefined' ? opts . progress : true
13
+ opts . markdown = typeof opts . markdown !== 'undefined' ? opts . markdown : false
13
14
14
15
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 ? '- ' : ''
15
20
16
21
var summary = summarize ( )
17
22
var output = summary . output
@@ -24,23 +29,23 @@ module.exports = function (opts) {
24
29
25
30
summary . on ( 'test.end' , function ( test ) {
26
31
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 ) )
28
33
} 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 ) )
30
35
}
31
36
} )
32
37
33
38
if ( opts . progress ) {
34
39
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 ) )
36
41
} )
37
42
38
43
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 ) )
40
45
} )
41
46
42
47
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 ) )
44
49
} )
45
50
}
46
51
@@ -69,17 +74,17 @@ module.exports = function (opts) {
69
74
function formatSummary ( res ) {
70
75
var output = [ LF ]
71
76
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 ) )
74
79
if ( res . pass ) {
75
- output . push ( format . green . escape ( 'pass: ' + res . pass ) )
80
+ output . push ( format . green . escape ( LIST + 'pass: ' + res . pass ) )
76
81
} else {
77
- output . push ( format . cyan . escape ( 'pass: ' + res . pass ) )
82
+ output . push ( format . cyan . escape ( LIST + 'pass: ' + res . pass ) )
78
83
}
79
84
if ( res . fail ) {
80
- output . push ( format . red . escape ( 'fail: ' + res . fail ) )
85
+ output . push ( format . red . escape ( LIST + 'fail: ' + res . fail ) )
81
86
} else {
82
- output . push ( format . cyan . escape ( 'fail: ' + res . fail ) )
87
+ output . push ( format . cyan . escape ( LIST + 'fail: ' + res . fail ) )
83
88
}
84
89
return output . join ( LF )
85
90
}
@@ -93,7 +98,7 @@ module.exports = function (opts) {
93
98
return output . join ( LF )
94
99
}
95
100
96
- function splitter ( s ) {
101
+ function barSplitter ( s ) {
97
102
var len = s && s . length || 0
98
103
var max = 80
99
104
var left = max - len >> 1
@@ -102,6 +107,13 @@ module.exports = function (opts) {
102
107
)
103
108
}
104
109
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
+
105
117
function repeat ( str , n ) {
106
118
if ( str . repeat ) {
107
119
return str . repeat ( n )
@@ -116,7 +128,7 @@ module.exports = function (opts) {
116
128
Object . keys ( fail ) . map ( function ( name ) {
117
129
var res = [ format . cyan . underline . escape ( '# ' + name ) ]
118
130
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 ) )
120
132
res . push ( prettifyError ( assertion ) )
121
133
} )
122
134
return res . join ( LF )
@@ -128,7 +140,9 @@ module.exports = function (opts) {
128
140
129
141
function prettifyError ( assertion ) {
130
142
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
+ } )
132
146
var stack = assertion . error . stack
133
147
if ( stack ) {
134
148
stack = stack . split ( LF )
0 commit comments