@@ -5,6 +5,7 @@ const path = require('path');
55const plur = require ( 'plur' ) ;
66const stripAnsi = require ( 'strip-ansi' ) ;
77const supertap = require ( 'supertap' ) ;
8+ const indentString = require ( 'indent-string' ) ;
89
910const prefixTitle = require ( './prefix-title' ) ;
1011
@@ -74,7 +75,7 @@ class TapReporter {
7475 if ( this . stats ) {
7576 this . reportStream . write ( supertap . finish ( {
7677 crashed : this . crashCount ,
77- failed : this . stats . failedHooks + this . stats . failedTests ,
78+ failed : this . stats . failedTests + this . stats . remainingTests ,
7879 passed : this . stats . passedTests + this . stats . passedKnownFailingTests ,
7980 skipped : this . stats . skippedTests ,
8081 todo : this . stats . todoTests
@@ -118,6 +119,21 @@ class TapReporter {
118119 } ) + os . EOL ) ;
119120 }
120121
122+ writeComment ( evt , { error = false , title = this . prefixTitle ( evt . testFile , evt . title ) } ) {
123+ let formattedTitle = title ;
124+ if ( error ) {
125+ formattedTitle = `Failed hook: ${ formattedTitle } ` ;
126+ }
127+
128+ this . reportStream . write ( `# ${ stripAnsi ( formattedTitle ) } ${ os . EOL } ` ) ;
129+ if ( evt . logs ) {
130+ for ( const log of evt . logs ) {
131+ const logLines = indentString ( log , 4 ) . replace ( / ^ { 4 } / , ' # ' ) ;
132+ this . reportStream . write ( `${ logLines } ${ os . EOL } ` ) ;
133+ }
134+ }
135+ }
136+
121137 consumeStateChange ( evt ) { // eslint-disable-line complexity
122138 const fileStats = this . stats && evt . testFile ? this . stats . byFile . get ( evt . testFile ) : null ;
123139
@@ -126,10 +142,10 @@ class TapReporter {
126142 // Ignore
127143 break ;
128144 case 'hook-failed' :
129- this . writeTest ( evt , { passed : false , todo : false , skip : false } ) ;
145+ this . writeComment ( evt , { error : true } ) ;
130146 break ;
131147 case 'hook-finished' :
132- this . writeTest ( evt , { passed : true , todo : false , skip : false } ) ;
148+ this . writeComment ( evt , { } ) ;
133149 break ;
134150 case 'internal-error' :
135151 this . writeCrash ( evt ) ;
@@ -179,7 +195,7 @@ class TapReporter {
179195 if ( fileStats . declaredTests === 0 ) {
180196 this . writeCrash ( evt , `No tests found in ${ path . relative ( '.' , evt . testFile ) } ` ) ;
181197 } else if ( ! this . failFastEnabled && fileStats . remainingTests > 0 ) {
182- this . writeCrash ( evt , `${ fileStats . remainingTests } ${ plur ( 'test' , fileStats . remainingTests ) } remaining in ${ path . relative ( '.' , evt . testFile ) } ` ) ;
198+ this . writeComment ( evt , { title : `${ fileStats . remainingTests } ${ plur ( 'test' , fileStats . remainingTests ) } remaining in ${ path . relative ( '.' , evt . testFile ) } ` } ) ;
183199 }
184200 }
185201
0 commit comments