11export interface Fail {
22 message : string
33 details ?: string
4+ logs ?: string [ ]
5+ }
6+
7+ export interface Pass {
8+ message : string
9+ logs ?: string [ ]
410}
511
612export interface ParserOutput {
713 ok : boolean
8- passed : Array < { message : string } >
9- failed : Array < Fail >
14+ passed : Pass [ ]
15+ failed : Fail [ ]
16+ logs : string [ ]
1017}
1118
1219const r = {
20+ start : / ^ 1 \. \. [ 0 - 9 ] + $ / ,
1321 fail : / ^ n o t o k \d + \s ( \- \s ) ? ( .+ ) + $ / ,
1422 pass : / ^ o k \d + \s ( \- \s ) ? ( .+ ) + $ / ,
1523 details : / ^ # \s { 2 } ( .+ ) $ / ,
24+ ignore : / ^ # \s + ( t e s t s | p a s s | f a i l | s k i p ) \s + [ 0 - 9 ] + $ / ,
1625}
1726
1827const detect = ( type : 'fail' | 'pass' | 'details' , text : string ) => r [ type ] . exec ( text )
1928
2029const parser = ( text : string ) : ParserOutput => {
21- const lines = text . split ( '\n' )
30+ const lineList = text . split ( '\n' )
31+ // start after 1..n output
32+ const startingPoint = lineList . findIndex ( ( t ) => t . match ( r . start ) )
33+ const lines = lineList . slice ( startingPoint + 1 )
2234
2335 const result : ParserOutput = {
2436 ok : true ,
2537 passed : [ ] ,
2638 failed : [ ] ,
39+ logs : [ ] ,
2740 }
2841
2942 // temporary holder of error detail strings
3043 let currentDetails : string | null = null
44+ let logs : string [ ] = [ ]
3145
3246 const addCurrentDetails = ( ) => {
3347 const failLength : number = result . failed . length
@@ -44,7 +58,12 @@ const parser = (text: string): ParserOutput => {
4458 // be optimistic! check for success
4559 const isPass = detect ( 'pass' , line )
4660 if ( ! ! isPass ) {
47- result . passed . push ( { message : isPass [ 2 ] . trim ( ) } )
61+ const pass : Pass = { message : isPass [ 2 ] . trim ( ) }
62+ if ( logs . length ) {
63+ pass . logs = logs
64+ logs = [ ]
65+ }
66+ result . passed . push ( pass )
4867 addCurrentDetails ( )
4968 continue
5069 }
@@ -54,7 +73,12 @@ const parser = (text: string): ParserOutput => {
5473 if ( ! ! isFail ) {
5574 result . ok = false
5675 addCurrentDetails ( )
57- result . failed . push ( { message : isFail [ 2 ] . trim ( ) } )
76+ const fail : Fail = { message : isFail [ 2 ] . trim ( ) }
77+ if ( logs . length ) {
78+ fail . logs = logs
79+ logs = [ ]
80+ }
81+ result . failed . push ( fail )
5882 continue
5983 }
6084
@@ -68,6 +92,13 @@ const parser = (text: string): ParserOutput => {
6892 // @ts -ignore ignore as it must be a string
6993 currentDetails += `\n${ lineDetails } `
7094 }
95+ continue
96+ }
97+
98+ if ( ! r . ignore . exec ( line ) ) {
99+ // must be a log, associate with the next test
100+ logs . push ( line )
101+ result . logs . push ( line )
71102 }
72103 }
73104 addCurrentDetails ( )
0 commit comments