@@ -2047,7 +2047,7 @@ function run() {
2047
2047
. trim ( ) ;
2048
2048
const diffChecker = new DiffChecker_1 . DiffChecker ( codeCoverageNew , codeCoverageOld ) ;
2049
2049
let messageToPost = `Code coverage diff between base branch:${ branchNameBase } and head branch: ${ branchNameHead } \n` ;
2050
- const coverageDetails = diffChecker . getCoverageDetails ( ! fullCoverage , `${ currentDirectory } /` , delta ) ;
2050
+ const coverageDetails = diffChecker . getCoverageDetails ( ! fullCoverage , `${ currentDirectory } /` ) ;
2051
2051
if ( coverageDetails . length === 0 ) {
2052
2052
messageToPost =
2053
2053
'No changes to code coverage between the base branch and the head branch' ;
@@ -2063,6 +2063,10 @@ function run() {
2063
2063
body : messageToPost ,
2064
2064
issue_number : prNumber
2065
2065
} ) ;
2066
+ // check if the test coverage is falling below delta/tolerance.
2067
+ if ( diffChecker . checkIfTestCoverageFallsBelowDelta ( delta ) ) {
2068
+ throw Error ( `Current PR reduces the test percentage by ${ delta } ` ) ;
2069
+ }
2066
2070
}
2067
2071
catch ( error ) {
2068
2072
core . setFailed ( error ) ;
@@ -6711,11 +6715,11 @@ class DiffChecker {
6711
6715
}
6712
6716
}
6713
6717
}
6714
- getCoverageDetails ( diffOnly , currentDirectory , delta ) {
6718
+ getCoverageDetails ( diffOnly , currentDirectory ) {
6715
6719
const keys = Object . keys ( this . diffCoverageReport ) ;
6716
6720
const returnStrings = [ ] ;
6717
6721
for ( const key of keys ) {
6718
- if ( this . compareCoverageValues ( this . diffCoverageReport [ key ] , delta ) !== 0 ) {
6722
+ if ( this . compareCoverageValues ( this . diffCoverageReport [ key ] ) !== 0 ) {
6719
6723
returnStrings . push ( this . createDiffLine ( key . replace ( currentDirectory , '' ) , this . diffCoverageReport [ key ] ) ) ;
6720
6724
}
6721
6725
else {
@@ -6726,6 +6730,23 @@ class DiffChecker {
6726
6730
}
6727
6731
return returnStrings ;
6728
6732
}
6733
+ checkIfTestCoverageFallsBelowDelta ( delta ) {
6734
+ const keys = Object . keys ( this . diffCoverageReport ) ;
6735
+ for ( const key of keys ) {
6736
+ const diffCoverageData = this . diffCoverageReport [ key ] ;
6737
+ const keys = Object . keys ( diffCoverageData ) ;
6738
+ for ( const key of keys ) {
6739
+ if ( diffCoverageData [ key ] . oldPct !== diffCoverageData [ key ] . newPct ) {
6740
+ const oldValue = Number ( diffCoverageData [ key ] . oldPct ) ;
6741
+ const newValue = Number ( diffCoverageData [ key ] . newPct ) ;
6742
+ if ( oldValue - newValue > delta ) {
6743
+ return true ;
6744
+ }
6745
+ }
6746
+ }
6747
+ }
6748
+ return false ;
6749
+ }
6729
6750
createDiffLine ( name , diffFileCoverageData ) {
6730
6751
if ( ! diffFileCoverageData . branches . oldPct ) {
6731
6752
return `**${ name } ** | **${ diffFileCoverageData . statements . newPct } ** | **${ diffFileCoverageData . branches . newPct } ** | **${ diffFileCoverageData . functions . newPct } ** | **${ diffFileCoverageData . lines . newPct } **` ;
@@ -6735,15 +6756,10 @@ class DiffChecker {
6735
6756
}
6736
6757
return `${ name } | ~~${ diffFileCoverageData . statements . oldPct } ~~ **${ diffFileCoverageData . statements . newPct } ** | ~~${ diffFileCoverageData . branches . oldPct } ~~ **${ diffFileCoverageData . branches . newPct } ** | ~~${ diffFileCoverageData . functions . oldPct } ~~ **${ diffFileCoverageData . functions . newPct } ** | ~~${ diffFileCoverageData . lines . oldPct } ~~ **${ diffFileCoverageData . lines . newPct } **` ;
6737
6758
}
6738
- compareCoverageValues ( diffCoverageData , delta ) {
6759
+ compareCoverageValues ( diffCoverageData ) {
6739
6760
const keys = Object . keys ( diffCoverageData ) ;
6740
6761
for ( const key of keys ) {
6741
6762
if ( diffCoverageData [ key ] . oldPct !== diffCoverageData [ key ] . newPct ) {
6742
- const oldValue = Number ( diffCoverageData [ key ] . oldPct ) ;
6743
- const newValue = Number ( diffCoverageData [ key ] . newPct ) ;
6744
- if ( oldValue - newValue > delta ) {
6745
- throw Error ( `Current PR reduces the test percentage by ${ delta } ` ) ;
6746
- }
6747
6763
return 1 ;
6748
6764
}
6749
6765
}
0 commit comments