@@ -6024,6 +6024,28 @@ function uncovered(file, options) {
60246024 . join ( ", " ) ;
60256025}
60266026
6027+ /**
6028+ * Compares two arrays of objects and returns with unique lines update
6029+ * @param {number } pdiff value from diff percentage
6030+ * @returns {string } emoji string for negative/positive pdiff
6031+ */
6032+ const renderEmoji = pdiff => {
6033+ if ( pdiff < 0 ) return "🔴" ;
6034+ if ( pdiff >= 0 ) return "🟢" ;
6035+ } ;
6036+
6037+ /**
6038+ * Compares two arrays of objects and returns with unique lines update
6039+ * @param {Array } otherArray
6040+ * @returns {Function } function with filtering non original lines
6041+ */
6042+ const comparer = otherArray => current =>
6043+ otherArray . filter (
6044+ other =>
6045+ other . lines . found === current . lines . found &&
6046+ other . lines . hit === current . lines . hit ,
6047+ ) . length === 0 ;
6048+
60276049/**
60286050 * Github comment for monorepo
60296051 * @param {Array<{packageName, lcovPath}> } lcovArrayForMonorepo
@@ -6046,15 +6068,14 @@ function commentForMonorepo(
60466068 const plus = pdiff > 0 ? "+" : "" ;
60476069 const arrow = pdiff === 0 ? "" : pdiff < 0 ? "▾" : "▴" ;
60486070
6049- const getColor = ( ) => {
6050- if ( pdiff === 0 ) return 'inherit' ;
6051- if ( pdiff < 0 ) return 'red' ;
6052- if ( pdiff > 0 ) return 'green' ;
6053- } ;
6054-
6055- const diffTh = `<div style="color:${ getColor } ;"}>${ th ( arrow , " " , plus , pdiff . toFixed ( 2 ) , "%" ) } </div>` ;
6071+ const pdiffHtml = baseLcov ? th ( renderEmoji ( pdiff ) , " " , arrow , " " , plus , pdiff . toFixed ( 2 ) , "%" ) : "" ;
6072+ let report = lcovObj . lcov ;
60566073
6057- const pdiffHtml = baseLcov ? diffTh : "" ;
6074+ if ( baseLcov ) {
6075+ const onlyInLcov = lcovObj . lcov . filter ( comparer ( baseLcov ) ) ;
6076+ const onlyInBefore = baseLcov . filter ( comparer ( lcovObj . lcov ) ) ;
6077+ report = onlyInBefore . concat ( onlyInLcov ) ;
6078+ }
60586079
60596080 return `${ table (
60606081 tbody (
@@ -6066,7 +6087,7 @@ function commentForMonorepo(
60666087 ) ,
60676088 ) } \n\n ${ details (
60686089 summary ( "Coverage Report" ) ,
6069- tabulate ( lcovObj . lcov , options ) ,
6090+ tabulate ( report , options ) ,
60706091 ) } <br/>`;
60716092 } ) ;
60726093
@@ -6088,15 +6109,23 @@ function comment(lcov, before, options) {
60886109 const plus = pdiff > 0 ? "+" : "" ;
60896110 const arrow = pdiff === 0 ? "" : pdiff < 0 ? "▾" : "▴" ;
60906111
6091- const pdiffHtml = before ? th ( arrow , " " , plus , pdiff . toFixed ( 2 ) , "%" ) : "" ;
6112+ const pdiffHtml = before ? th ( renderEmoji ( pdiff ) , " " , arrow , " " , plus , pdiff . toFixed ( 2 ) , "%" ) : "" ;
6113+
6114+ let report = lcov ;
6115+
6116+ if ( before ) {
6117+ const onlyInLcov = lcov . filter ( comparer ( before ) ) ;
6118+ const onlyInBefore = before . filter ( comparer ( lcov ) ) ;
6119+ report = onlyInBefore . concat ( onlyInLcov ) ;
6120+ }
60926121
60936122 return fragment (
60946123 `Coverage after merging ${ b ( options . head ) } into ${ b (
60956124 options . base ,
60966125 ) } <p></p>`,
60976126 table ( tbody ( tr ( th ( percentage ( lcov ) . toFixed ( 2 ) , "%" ) , pdiffHtml ) ) ) ,
60986127 "\n\n" ,
6099- details ( summary ( "Coverage Report" ) , tabulate ( lcov , options ) ) ,
6128+ details ( summary ( "Coverage Report" ) , tabulate ( report , options ) ) ,
61006129 ) ;
61016130}
61026131
@@ -6314,7 +6343,7 @@ async function main() {
63146343 commit : context . payload . pull_request . head . sha ,
63156344 prefix : `${ process . env . GITHUB_WORKSPACE } /` ,
63166345 head : context . payload . pull_request . head . ref ,
6317- base : context . payload . pull_request . base . ref ,
6346+ base : context . payload . pull_request . base . ref
63186347 } ;
63196348
63206349 const lcov = ! monorepoBasePath && ( await parse$1 ( raw ) ) ;
0 commit comments