1- import { details , summary , b , fragment , table , tbody , tr , th } from "./html" ;
1+ import { details , summary , b , fragment , table , tbody , tr , th , p } from "./html" ;
22import { percentage } from "./lcov" ;
33import { tabulate } from "./tabulate" ;
44
@@ -9,10 +9,19 @@ import { tabulate } from "./tabulate";
99 */
1010const renderEmoji = ( pdiff ) => {
1111 if ( pdiff . toFixed ( 2 ) < 0 ) return "❌" ;
12-
1312 return "✅" ;
1413} ;
1514
15+ const renderArrow = ( pdiff ) => {
16+ if ( pdiff < 0 ) {
17+ return "▾" ;
18+ }
19+ if ( pdiff > 0 ) {
20+ return "▴" ;
21+ }
22+ return "" ;
23+ } ;
24+
1625/**
1726 * Compares two arrays of objects and returns with unique lines update
1827 * @param {Array } otherArray
@@ -25,6 +34,50 @@ const comparer = (otherArray) => (current) =>
2534 other . lines . hit === current . lines . hit ,
2635 ) . length === 0 ;
2736
37+ const renderLcov = ( lcov , base , appTitle , options ) => {
38+ const maxLines = options . maxLines || 15 ;
39+ const pbefore = base ? percentage ( base ) : 0 ;
40+ const pafter = base ? percentage ( lcov ) : 0 ;
41+ const pdiff = pafter - pbefore ;
42+ const plus = pdiff > 0 ? "+" : "" ;
43+
44+ let report = lcov ;
45+ if ( base ) {
46+ const onlyInLcov = lcov . filter ( comparer ( base ) ) ;
47+ const onlyInBefore = base . filter ( comparer ( lcov ) ) ;
48+ report = onlyInBefore . concat ( onlyInLcov ) ;
49+ }
50+
51+ const h = th ( percentage ( lcov ) . toFixed ( 2 ) , "%" ) ;
52+
53+ const row = [ ] ;
54+ if ( appTitle ) {
55+ row . push ( th ( appTitle ) ) ;
56+ }
57+ row . push ( h ) ;
58+ if ( base ) {
59+ const arrow = renderArrow ( pdiff ) ;
60+ row . push (
61+ th (
62+ renderEmoji ( pdiff ) ,
63+ " " ,
64+ arrow ,
65+ " " ,
66+ plus ,
67+ pdiff . toFixed ( 2 ) ,
68+ "%" ,
69+ ) ,
70+ ) ;
71+ }
72+ return [
73+ table ( tbody ( tr ( ...row ) ) ) ,
74+ report . length > maxLines
75+ ? p ( "Coverage Report too long to display" )
76+ : details ( summary ( "Coverage Report" ) , tabulate ( report , options ) ) ,
77+ "<br/>" ,
78+ ] . join ( "" ) ;
79+ } ;
80+
2881/**
2982 * Github comment for monorepo
3083 * @param {Array<{packageName, lcovPath}> } lcovArrayForMonorepo
@@ -36,60 +89,23 @@ const commentForMonorepo = (
3689 lcovBaseArrayForMonorepo ,
3790 options ,
3891) => {
39- const { base } = options ;
40- const html = lcovArrayForMonorepo . map ( ( lcovObj ) => {
41- const baseLcov = lcovBaseArrayForMonorepo . find (
42- ( el ) => el . packageName === lcovObj . packageName ,
43- ) ;
44-
45- const pbefore = baseLcov ? percentage ( baseLcov . lcov ) : 0 ;
46- const pafter = baseLcov ? percentage ( lcovObj . lcov ) : 0 ;
47- const pdiff = pafter - pbefore ;
48- const plus = pdiff > 0 ? "+" : "" ;
49-
50- let arrow = "" ;
51- if ( pdiff < 0 ) {
52- arrow = "▾" ;
53- } else if ( pdiff > 0 ) {
54- arrow = "▴" ;
55- }
56-
57- const pdiffHtml = baseLcov
58- ? th (
59- renderEmoji ( pdiff ) ,
60- " " ,
61- arrow ,
62- " " ,
63- plus ,
64- pdiff . toFixed ( 2 ) ,
65- "%" ,
66- )
67- : "" ;
68- let report = lcovObj . lcov ;
69-
70- if ( baseLcov ) {
71- const onlyInLcov = lcovObj . lcov . filter ( comparer ( baseLcov ) ) ;
72- const onlyInBefore = baseLcov . filter ( comparer ( lcovObj . lcov ) ) ;
73- report = onlyInBefore . concat ( onlyInLcov ) ;
74- }
75-
76- return `${ table (
77- tbody (
78- tr (
79- th ( lcovObj . packageName ) ,
80- th ( percentage ( lcovObj . lcov ) . toFixed ( 2 ) , "%" ) ,
81- pdiffHtml ,
82- ) ,
83- ) ,
84- ) } \n\n ${ details (
85- summary ( "Coverage Report" ) ,
86- tabulate ( report , options ) ,
87- ) } <br/>`;
88- } ) ;
92+ const body = lcovArrayForMonorepo
93+ . map ( ( lcovObj ) => {
94+ const baseLcov = lcovBaseArrayForMonorepo . find (
95+ ( el ) => el . packageName === lcovObj . packageName ,
96+ ) ;
97+ return renderLcov (
98+ lcovObj . lcov ,
99+ baseLcov && baseLcov . lcov ,
100+ lcovObj . packageName ,
101+ options ,
102+ ) ;
103+ } )
104+ . join ( "" ) ;
89105
106+ const { base } = options ;
90107 const title = `Coverage after merging into ${ b ( base ) } <p></p>` ;
91-
92- return fragment ( title , html . join ( "" ) ) ;
108+ return fragment ( title , body ) ;
93109} ;
94110
95111/**
@@ -99,43 +115,8 @@ const commentForMonorepo = (
99115 */
100116const comment = ( lcov , before , options ) => {
101117 const { appName, base } = options ;
102- const pbefore = before ? percentage ( before ) : 0 ;
103- const pafter = before ? percentage ( lcov ) : 0 ;
104- const pdiff = pafter - pbefore ;
105- const plus = pdiff > 0 ? "+" : "" ;
106-
107- let arrow = "" ;
108- if ( pdiff < 0 ) {
109- arrow = "▾" ;
110- } else if ( pdiff > 0 ) {
111- arrow = "▴" ;
112- }
113-
114- const pdiffHtml = before
115- ? th ( renderEmoji ( pdiff ) , " " , arrow , " " , plus , pdiff . toFixed ( 2 ) , "%" )
116- : "" ;
117-
118- let report = lcov ;
119-
120- if ( before ) {
121- const onlyInLcov = lcov . filter ( comparer ( before ) ) ;
122- const onlyInBefore = before . filter ( comparer ( lcov ) ) ;
123- report = onlyInBefore . concat ( onlyInLcov ) ;
124- }
125-
126118 const title = `Coverage after merging into ${ b ( base ) } <p></p>` ;
127- const header = appName
128- ? tbody (
129- tr ( th ( appName ) , th ( percentage ( lcov ) . toFixed ( 2 ) , "%" ) , pdiffHtml ) ,
130- )
131- : tbody ( tr ( th ( percentage ( lcov ) . toFixed ( 2 ) , "%" ) , pdiffHtml ) ) ;
132-
133- return fragment (
134- title ,
135- table ( header ) ,
136- "\n\n" ,
137- details ( summary ( "Coverage Report" ) , tabulate ( report , options ) ) ,
138- ) ;
119+ return fragment ( title , renderLcov ( lcov , before , appName , options ) ) ;
139120} ;
140121
141122/**
0 commit comments