File tree Expand file tree Collapse file tree 2 files changed +27
-5
lines changed Top Open diff view settings Expand file tree Collapse file tree 2 files changed +27
-5
lines changed Top Open diff view settings Original file line number Diff line number Diff line change @@ -15,6 +15,17 @@ ok 2 - Should also pass
1515ok 1 - Should pass
1616not ok 2 - This one fails
1717ok 3 - Also passes
18+ `
19+ expect ( parser ( example ) . ok ) . toBe ( false )
20+ } )
21+ test ( 'should detect failure if no tests passed' , ( ) => {
22+ const example = `
23+ # Starting...
24+ # 1 test suites found.
25+
26+ # FAIL __tests__/sum.test.js
27+
28+ not ok 1 ● sum › should add two numbers together
1829`
1930 expect ( parser ( example ) . ok ) . toBe ( false )
2031 } )
Original file line number Diff line number Diff line change @@ -3,16 +3,27 @@ interface ParserOutput {
33 message ?: string
44}
55
6+ const fail = / ^ n o t o k \d + .{ 1 } ( .+ ) + $ /
7+ const ok = / ^ o k \d + .{ 1 } /
8+
69const parser = ( text : string ) : ParserOutput => {
710 const lines = text . split ( '\n' )
11+ let hasPass = false
812 for ( const line of lines ) {
9- // parse failed test
10- const match = line . match ( / ^ n o t o k \d + - ( .+ ) + / )
11- if ( ! ! match ) {
12- return { ok : false , message : match [ 1 ] }
13+ if ( line . length ) {
14+ // parse failed test
15+ const failRegex = fail . exec ( line )
16+ if ( ! ! failRegex ) {
17+ return { ok : false , message : failRegex [ 1 ] }
18+ }
19+ if ( ! hasPass ) {
20+ if ( ! ! ok . exec ( line ) ) {
21+ hasPass = true
22+ }
23+ }
1324 }
1425 }
15- return { ok : true }
26+ return { ok : hasPass }
1627}
1728
1829export default parser
You can’t perform that action at this time.
0 commit comments