1
- import Table from "terminal-table " ;
1
+ import Table , { Cell } from "cli-table3 " ;
2
2
import { CoverageData } from "../getCoverage" ;
3
3
import chalk from "chalk" ;
4
4
5
5
const coverageTable = new Table ( {
6
- leftPadding : 1 ,
7
- rightPadding : 1 ,
8
- borderStyle : 2
6
+ chars : { mid : "" , "left-mid" : "" , "mid-mid" : "" , "right-mid" : "" } ,
7
+ colAligns : [ "left" , "right" , "right" , "right" , "right" ] ,
8
+ style : { "padding-left" : 1 , "padding-right" : 1 }
9
9
} ) ;
10
10
11
11
const calculatePercantage = ( correct : number , total : number ) : number => {
@@ -27,7 +27,6 @@ export const generate = (
27
27
{ fileCounts, percentage, total, covered, uncovered } : CoverageData ,
28
28
threshold : number
29
29
) : string => {
30
- let row = 1 ;
31
30
const headers = [
32
31
"filenames" + chalk . gray ( ` (${ fileCounts . size } )` ) ,
33
32
"percent" + chalk . gray ( ` (${ percentage . toFixed ( 2 ) } %)` ) ,
@@ -41,13 +40,6 @@ export const generate = (
41
40
headers . map ( ( ) => chalk . gray ( "---" ) )
42
41
) ;
43
42
44
- coverageTable . attrRange (
45
- { column : [ 1 , 5 ] } ,
46
- {
47
- align : "right"
48
- }
49
- ) ;
50
-
51
43
fileCounts . forEach (
52
44
(
53
45
{
@@ -56,25 +48,26 @@ export const generate = (
56
48
} : { totalCount : number ; correctCount : number } ,
57
49
filename : string
58
50
) => {
59
- row ++ ;
51
+ const colorCell = ( cell : Cell ) : Cell => {
52
+ const color =
53
+ Math . floor ( calculatePercantage ( correctCount , totalCount ) ) >= threshold
54
+ ? chalk . green
55
+ : chalk . red ;
56
+ if ( typeof cell === "object" && "content" in cell ) {
57
+ return { ...cell , content : color ( cell . content ) } ;
58
+ }
60
59
61
- coverageTable . push ( [
62
- filename ,
63
- calculatePercantageWithString ( correctCount , totalCount ) ,
64
- totalCount ,
65
- correctCount ,
66
- totalCount - correctCount
67
- ] ) ;
60
+ return color ( cell ) ;
61
+ } ;
68
62
69
- coverageTable . attrRange (
70
- { row : [ row ] } ,
71
- {
72
- color :
73
- Math . floor ( calculatePercantage ( correctCount , totalCount ) ) >=
74
- threshold
75
- ? "green"
76
- : "red"
77
- }
63
+ coverageTable . push (
64
+ [
65
+ filename ,
66
+ calculatePercantageWithString ( correctCount , totalCount ) ,
67
+ totalCount ,
68
+ correctCount ,
69
+ totalCount - correctCount
70
+ ] . map ( ( val ) => colorCell ( val ) )
78
71
) ;
79
72
}
80
73
) ;
0 commit comments