1- const isTap = / ^ # T A P / m;
2- const finalTestNumber = / ^ 1 ..( [ 0 - 9 + ] ) $ / m;
3- const testError = / ^ # E \s + ( .+ ) $ / m;
1+ const regex = {
2+ isTap : / ^ # T A P / m,
3+ test : / ^ [ n o t ] ? o k [ 0 - 9 ] + - / m,
4+ finalTest : / ^ 1 ..( [ 0 - 9 + ] ) $ / m,
5+ error : / ^ # E \s + ( .+ ) $ / m,
6+ log : / ^ (? ! # T A P ) (? ! ( n o t ) ? o k [ 0 - 9 ] + - ) (? ! 1 ..[ 0 - 9 ] + ) (? ! # E \s ) ( .* ) $ /
7+ } ;
48
5- function formatFailureMessage ( message : string ) : string {
9+ function formatFeedback ( message : string ) : string {
610 return message . split ( '_' ) . join ( ' ' ) ;
711}
812
13+ function log ( data : string ) : void {
14+ var logs = data . match ( regex . log ) ;
15+ if ( logs && logs . length > 0 ) {
16+ logs . forEach ( ( line : string ) => {
17+ try {
18+ console . dir ( JSON . parse ( JSON . stringify ( line ) ) ) ;
19+ } catch ( e ) {
20+ console . log ( data ) ;
21+ }
22+ } ) ;
23+ }
24+ }
25+
926export default function parseTap ( data : string ) : ParseFinal {
1027
11- if ( ! data || ! data . match ( isTap ) ) {
28+ // capture any abnormal data as a log
29+ log ( data ) ;
30+
31+ if ( ! data || ! data . match ( regex . isTap ) ) {
1232 console . log ( 'No TAP output: ' , data ) ;
1333 return ;
1434 }
1535
16- if ( ! data . match ( finalTestNumber ) ) {
36+ if ( ! data . match ( regex . finalTest ) ) {
1737 console . log ( 'Could not parse final test number: ' , data ) ;
1838 return ;
1939 }
20- let finalTest : number = parseInt ( data . match ( finalTestNumber ) [ 1 ] , 10 ) ;
40+
41+ let finalTest : number = parseInt ( data . match ( regex . finalTest ) [ 1 ] , 10 ) ;
2142
2243 let final : ParseFinal = null ;
2344
24- if ( data . match ( testError ) ) {
45+ if ( data . match ( regex . error ) ) {
2546
26- // fail
47+ // first FAILing test
2748
2849 let failingLineRegex = new RegExp ( `^not ok ${ finalTest } - (.+)$` , 'm' ) ;
2950 let line : string = data . match ( failingLineRegex ) [ 1 ] ;
@@ -36,21 +57,21 @@ export default function parseTap(data: string): ParseFinal {
3657 console . log ( 'No matching taskPosition' , data ) ;
3758 }
3859
39- let message : string = formatFailureMessage ( line . match ( / \. t e s t _ ( .+ ) $ / ) [ 1 ] ) ;
60+ let message : string = formatFeedback ( line . match ( / \. t e s t _ ( .+ ) $ / ) [ 1 ] ) ;
4061 if ( ! message || typeof message !== 'string' ) {
4162 console . log ( 'Error with test. There is no valid test message: ' , data ) ;
4263 message = '' ;
4364 }
4465
4566 final = {
4667 completed : false ,
47- msg : formatFailureMessage ( message ) ,
68+ msg : formatFeedback ( message ) ,
4869 taskPosition : taskPosition - 1 ,
4970 timedOut : false // TODO
5071 } ;
5172 } else {
5273
53- // all pass
74+ // all tests PASS
5475
5576 let finalPassRegex = new RegExp ( `^ok ${ finalTest } - (.+)$` , 'm' ) ;
5677 let line : string = data . match ( finalPassRegex ) [ 1 ] ;
0 commit comments