File tree Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -39,4 +39,32 @@ not ok 4 - Second to fail
3939`
4040 expect ( parser ( example ) . message ) . toBe ( 'First to fail' )
4141 } )
42+
43+ test ( 'should parse mocha tap example' , ( ) => {
44+ const example = `
45+ 1..3
46+ ok 1 itemList data should not be changed
47+ ok 2 sumItems shouldn't return NaN
48+ ok 3 sumItems should total numbers accurately
49+ # tests 3
50+ # pass 3
51+ # fail 0
52+ # skip 0
53+ `
54+ expect ( parser ( example ) . ok ) . toBe ( true )
55+ } )
56+
57+ test ( 'should return failure message for mocha tap example' , ( ) => {
58+ const example = `
59+ 1..3
60+ ok 1 itemList data should not be changed
61+ not ok 2 sumItems shouldn't return NaN
62+ ok 3 sumItems should total numbers accurately
63+ # tests 3
64+ # pass 2
65+ # fail 1
66+ # skip 0
67+ `
68+ expect ( parser ( example ) . message ) . toBe ( "sumItems shouldn't return NaN" )
69+ } )
4270} )
Original file line number Diff line number Diff line change @@ -3,8 +3,8 @@ interface ParserOutput {
33 message ?: string
44}
55
6- const fail = / ^ n o t o k \d + . { 1 } ( .+ ) + $ /
7- const ok = / ^ o k \d + . { 1 } /
6+ const fail = / ^ n o t o k \d + \s ( \- \s ) ? ( .+ ) + $ /
7+ const ok = / ^ o k /
88
99const parser = ( text : string ) : ParserOutput => {
1010 const lines = text . split ( '\n' )
@@ -14,7 +14,7 @@ const parser = (text: string): ParserOutput => {
1414 // parse failed test
1515 const failRegex = fail . exec ( line )
1616 if ( ! ! failRegex ) {
17- return { ok : false , message : failRegex [ 1 ] }
17+ return { ok : false , message : failRegex [ 2 ] }
1818 }
1919 if ( ! hasPass ) {
2020 if ( ! ! ok . exec ( line ) ) {
You can’t perform that action at this time.
0 commit comments