@@ -20,20 +20,39 @@ export interface ParserOutput {
20
20
}
21
21
22
22
const r = {
23
- start : / ^ 1 \. \. [ 0 - 9 ] + $ / ,
24
- fail : / ^ n o t o k \d + \s ( \- \s ) ? ( .+ ) + $ / ,
25
- pass : / ^ o k \d + \s ( \- \s ) ? ( .+ ) + $ / ,
26
- details : / ^ # \s { 2 } ( .+ ) $ / ,
27
- ignore : / ^ # \s + ( t e s t s | p a s s | f a i l | s k i p ) \s + [ 0 - 9 ] + $ / ,
23
+ start : / ^ ( n o t o k ) | ( o k ) / ,
24
+ fail : / ^ n o t o k (?< index > \d + ) \s ( \- \s ) ? (?< message > .+ ) $ / ,
25
+ pass : / ^ o k (?< index > \d + ) \s ( \- \s ) ? (?< message > .+ ) $ / ,
26
+ details : / ^ # \s { 2 } (?< message > .+ ) $ / ,
27
+ ignore : / ^ ( 1 \. \. [ 0 - 9 ] + ) | ( # \s + ( t e s t s | p a s s | f a i l | s k i p ) \s + [ 0 - 9 ] + ) $ / ,
28
28
}
29
29
30
- const detect = ( type : 'fail' | 'pass' | 'details' , text : string ) => r [ type ] . exec ( text )
30
+ const detect = ( type : 'fail' | 'pass' | 'details' , text : string ) => {
31
+ const match = r [ type ] . exec ( text )
32
+ if ( ! match ) {
33
+ return null
34
+ }
35
+ return match . groups
36
+ }
37
+
38
+ // see comment below for extracting logic into custom consumer later
39
+ const formatMessage = ( message : string ) : string => {
40
+ // specific for python tap.py output
41
+ const isTappy = message . match ( / ^ t e s t _ (?< underscoredMessage > .+ ) \s (?< testPath > .+ ) $ / )
42
+ if ( isTappy ?. groups ?. underscoredMessage ) {
43
+ return isTappy . groups . underscoredMessage . split ( '_' ) . join ( ' ' ) . trim ( )
44
+ }
45
+ return message . trim ( )
46
+ }
31
47
48
+ // TODO: consider creating custom TAP consumers for languages
49
+ // otherwise code here will eventually get out of hand
50
+ // currently supports: mocha, python tap.py
32
51
const parser = ( text : string ) : ParserOutput => {
33
52
const lineList = text . split ( '\n' )
34
53
// start after 1..n output
35
54
const startingPoint = lineList . findIndex ( ( t ) => t . match ( r . start ) )
36
- const lines = lineList . slice ( startingPoint + 1 )
55
+ const lines = lineList . slice ( startingPoint )
37
56
38
57
const result : ParserOutput = {
39
58
ok : true ,
@@ -59,10 +78,10 @@ const parser = (text: string): ParserOutput => {
59
78
if ( ! line . length ) {
60
79
continue
61
80
}
62
- // be optimistic! check for success
81
+ // be optimistic! check for success first
63
82
const isPass = detect ( 'pass' , line )
64
83
if ( ! ! isPass ) {
65
- const message = isPass [ 2 ] . trim ( )
84
+ const message = formatMessage ( isPass . message )
66
85
const pass : Pass = { message }
67
86
if ( logs . length ) {
68
87
pass . logs = logs
@@ -79,7 +98,7 @@ const parser = (text: string): ParserOutput => {
79
98
if ( ! ! isFail ) {
80
99
result . ok = false
81
100
addCurrentDetails ( )
82
- const message = isFail [ 2 ] . trim ( )
101
+ const message = formatMessage ( isFail . message )
83
102
const fail : Fail = { message }
84
103
if ( logs . length ) {
85
104
fail . logs = logs
@@ -93,7 +112,7 @@ const parser = (text: string): ParserOutput => {
93
112
// check for error details
94
113
const isDetails = detect ( 'details' , line )
95
114
if ( ! ! isDetails ) {
96
- const lineDetails : string = isDetails [ 1 ] . trim ( )
115
+ const lineDetails : string = isDetails . message . trim ( )
97
116
if ( ! currentDetails ) {
98
117
currentDetails = lineDetails
99
118
} else {
0 commit comments