@@ -2,7 +2,13 @@ import { coverageDiffer } from './coverageDiffer';
2
2
import { objectToMap , mapToObject } from './helpers' ;
3
3
import { getSummaryPercentages } from './helpers' ;
4
4
import { defaultOptions } from './index' ;
5
- import { IJsonSummary , IFileResultFormat , IDiffCheckResults } from './common' ;
5
+ import {
6
+ IJsonSummary ,
7
+ IFileResultFormat ,
8
+ IDiffCheckResults ,
9
+ ICoverageSummary ,
10
+ Criteria
11
+ } from './common' ;
6
12
/**
7
13
* Takes a json-summary formatted object (a diff) and checks if per-file
8
14
* coverage changed (increase/decrease).
@@ -26,26 +32,26 @@ export const diffChecker = (
26
32
27
33
diffMap . forEach ( ( v , k ) => {
28
34
const diffPercentages = getSummaryPercentages ( v ) ;
29
- const headPercentages = getSummaryPercentages ( head [ k ] ) ;
30
35
31
- const diffCriteria = checkCriteria . map (
32
- criteria => diffPercentages [ criteria ]
33
- ) ;
36
+ // Only check files that changed coverage.
37
+ if ( Object . values ( diffPercentages ) . some ( nonZeroTest ) ) {
38
+ const decreased = checkCoverageForCondition (
39
+ v ,
40
+ checkCriteria ,
41
+ coverageDecreased
42
+ ) ;
43
+ const belowTreshold = checkCoverageForCondition (
44
+ head [ k ] ,
45
+ checkCriteria ,
46
+ isBelowTreshold
47
+ ) ;
34
48
35
- const tresholdCriteria = checkCriteria . map (
36
- criteria => headPercentages [ criteria ]
37
- ) ;
49
+ // Coverage decreased on a file or under treshold, regress.
50
+ // Ignore the total field as we check only files.
51
+ if ( ( decreased || belowTreshold ) && k !== 'total' ) {
52
+ regression = true ;
53
+ }
38
54
39
- const decreased = diffCriteria . some ( coverageDecreased ) ;
40
- const belowTreshold = tresholdCriteria . some ( isBelowTreshold ) ;
41
-
42
- // Coverage decreased on a file or under treshold. Set regression flag true.
43
- if ( ( decreased || belowTreshold ) && k !== 'total' ) {
44
- regression = true ;
45
- }
46
-
47
- // Skip unchanged files.
48
- if ( diffCriteria . some ( nonZeroTest ) ) {
49
55
percentageMap . set ( k , {
50
56
deltas : {
51
57
...diffPercentages
@@ -69,3 +75,15 @@ export const diffChecker = (
69
75
70
76
return { files : mapToObject ( percentageMap ) , diff, totals, regression } ;
71
77
} ;
78
+
79
+ const checkCoverageForCondition = (
80
+ coverage : ICoverageSummary ,
81
+ checkCriteria : Criteria [ ] ,
82
+ condition : ( x : number ) => boolean
83
+ ) => {
84
+ const diffPercentages = getSummaryPercentages ( coverage ) ;
85
+
86
+ const values = checkCriteria . map ( criteria => diffPercentages [ criteria ] ) ;
87
+
88
+ return values . some ( condition ) ;
89
+ } ;
0 commit comments