@@ -194,6 +194,46 @@ function isFull(metrics: CoverageSummary): boolean {
194194 ) ;
195195}
196196
197+ /** why a row is left out of the table, or `null` when it is printed */
198+ function skipReason (
199+ metrics : CoverageSummary ,
200+ skipEmpty : boolean | undefined ,
201+ skipFull : boolean | undefined ,
202+ ) : "empty" | "full" | null {
203+ if ( skipEmpty && metrics . isEmpty ( ) ) return "empty" ;
204+ if ( skipFull && isFull ( metrics ) ) return "full" ;
205+ return null ;
206+ }
207+
208+ /** counts of skipped files when `skipFull` would leave the table without file rows, otherwise `null` */
209+ function hiddenTableCounts (
210+ root : ReportNode ,
211+ context : Context ,
212+ skipEmpty : boolean | undefined ,
213+ skipFull : boolean | undefined ,
214+ ) : { full : number ; empty : number } | null {
215+ if ( ! skipFull ) return null ;
216+
217+ const counts = { full : 0 , empty : 0 , shown : 0 } ;
218+ root . visit (
219+ context . getVisitor ( {
220+ onDetail ( node ) {
221+ const metrics = node . getCoverageSummary ( ) ! ;
222+
223+ if ( ! skipReason ( metrics , skipEmpty , skipFull ) ) counts . shown += 1 ;
224+ // empty files are hidden by `skipFull` too, but they are not "fully covered"
225+ else if ( metrics . isEmpty ( ) ) counts . empty += 1 ;
226+ else counts . full += 1 ;
227+ } ,
228+ } ) ,
229+ ) ;
230+ return counts . shown === 0 && counts . full + counts . empty > 0 ? counts : null ;
231+ }
232+
233+ function fileNoun ( count : number ) : string {
234+ return count === 1 ? "file" : "files" ;
235+ }
236+
197237function tableRow (
198238 node : ReportNode ,
199239 context : Context ,
@@ -207,10 +247,7 @@ function tableRow(
207247 const name = nodeName ( node ) ;
208248 const metrics = node . getCoverageSummary ( ) ! ;
209249 const isEmpty = metrics . isEmpty ( ) ;
210- if ( skipEmpty && isEmpty ) {
211- return "" ;
212- }
213- if ( skipFull && isFull ( metrics ) ) {
250+ if ( skipReason ( metrics , skipEmpty , skipFull ) ) {
214251 return "" ;
215252 }
216253
@@ -249,6 +286,7 @@ class TextReport extends ReportBase {
249286 declare skipFull : boolean | undefined ;
250287 declare nameWidth : number ;
251288 declare missingWidth : number ;
289+ declare hideTable : boolean ;
252290
253291 constructor ( opts ?: TextOptions ) {
254292 super ( opts ) ;
@@ -261,10 +299,23 @@ class TextReport extends ReportBase {
261299 this . cw = null ;
262300 this . skipEmpty = opts . skipEmpty ;
263301 this . skipFull = opts . skipFull ;
302+ this . hideTable = false ;
264303 }
265304
266305 onStart ( root : ReportNode , context : Context ) : void {
267306 this . cw = context . writer . writeFile ( this . file ) ;
307+ const counts = hiddenTableCounts ( root , context , this . skipEmpty , this . skipFull ) ;
308+ this . hideTable = counts !== null ;
309+ if ( counts ) {
310+ this . cw . println ( "No files with missing coverage." ) ;
311+ if ( counts . full > 0 ) {
312+ this . cw . println ( `${ counts . full } ${ fileNoun ( counts . full ) } fully covered.` ) ;
313+ }
314+ if ( counts . empty > 0 ) {
315+ this . cw . println ( `${ counts . empty } empty ${ fileNoun ( counts . empty ) } skipped.` ) ;
316+ }
317+ return ;
318+ }
268319 this . nameWidth = Math . max ( NAME_COL , findWidth ( root , context , nodeName , depthFor ) ) ;
269320 this . missingWidth = Math . max ( MISSING_COL , findWidth ( root , context , nodeMissing ) ) ;
270321
@@ -289,6 +340,9 @@ class TextReport extends ReportBase {
289340 }
290341
291342 onSummary ( node : ReportNode , context : Context ) : void {
343+ if ( this . hideTable ) {
344+ return ;
345+ }
292346 const nodeDepth = depthFor ( node ) ;
293347 const row = tableRow (
294348 node ,
@@ -310,7 +364,9 @@ class TextReport extends ReportBase {
310364 }
311365
312366 onEnd ( ) : void {
313- this . cw ! . println ( makeLine ( this . nameWidth , this . missingWidth ) ) ;
367+ if ( ! this . hideTable ) {
368+ this . cw ! . println ( makeLine ( this . nameWidth , this . missingWidth ) ) ;
369+ }
314370 this . cw ! . close ( ) ;
315371 }
316372}
0 commit comments