@@ -21,12 +21,14 @@ it('returns new thresholds if coverages are higher', () => {
2121 }
2222 const margin = 0
2323 const tolerance = 0
24+ const precision = 2
2425
2526 const newThresholds = getNewThresholds (
2627 thresholds ,
2728 coverages ,
2829 margin ,
2930 tolerance ,
31+ precision ,
3032 )
3133
3234 expect ( newThresholds ) . toStrictEqual ( {
@@ -52,17 +54,18 @@ it('only returns new thresholds if coverages are above the margin', () => {
5254 }
5355 const margin = 50
5456 const tolerance = 0
57+ const precision = 2
5558
5659 const newThresholds = getNewThresholds (
5760 thresholds ,
5861 coverages ,
5962 margin ,
6063 tolerance ,
64+ precision ,
6165 )
6266
6367 expect ( newThresholds ) . toStrictEqual ( {
6468 branches : { diff : 70 , next : 80 , prev : 10 } ,
65- functions : { diff : 50 , next : 70 , prev : 20 } ,
6669 } )
6770} )
6871
@@ -81,19 +84,20 @@ it('should return new thresholds if coverage - tolerance is higher than the curr
8184 }
8285 const margin = 0
8386 const tolerance = 10
87+ const precision = 2
8488
8589 const newThresholds = getNewThresholds (
8690 thresholds ,
8791 coverages ,
8892 margin ,
8993 tolerance ,
94+ precision ,
9095 )
9196
9297 expect ( newThresholds ) . toStrictEqual ( {
9398 branches : { diff : 60 , next : 70 , prev : 10 } ,
9499 functions : { diff : 40 , next : 60 , prev : 20 } ,
95100 lines : { diff : 20 , next : 50 , prev : 30 } ,
96- statements : { diff : 0 , next : 40 , prev : 40 } ,
97101 } )
98102} )
99103
@@ -112,13 +116,81 @@ it('should not return new thresholds if coverage - tolerance is lower than the c
112116 }
113117 const margin = 0
114118 const tolerance = 100
119+ const precision = 2
115120
116121 const newThresholds = getNewThresholds (
117122 thresholds ,
118123 coverages ,
119124 margin ,
120125 tolerance ,
126+ precision ,
121127 )
122128
123129 expect ( newThresholds ) . toStrictEqual ( { } )
124130} )
131+
132+ it ( 'should return new thresholds with a precision if set' , ( ) => {
133+ const thresholds = {
134+ branches : 10 ,
135+ functions : 20 ,
136+ lines : 30 ,
137+ statements : 40 ,
138+ }
139+ const coverages = {
140+ branches : { pct : 80.63 } ,
141+ functions : { pct : 70.15 } ,
142+ lines : { pct : 60.25 } ,
143+ statements : { pct : 50.89 } ,
144+ }
145+ const margin = 0
146+ const tolerance = 0
147+ const precision = 1
148+
149+ const newThresholds = getNewThresholds (
150+ thresholds ,
151+ coverages ,
152+ margin ,
153+ tolerance ,
154+ precision ,
155+ )
156+
157+ expect ( newThresholds ) . toStrictEqual ( {
158+ branches : { diff : 70.6 , next : 80.6 , prev : 10 } ,
159+ functions : { diff : 50.1 , next : 70.1 , prev : 20 } ,
160+ lines : { diff : 30.2 , next : 60.2 , prev : 30 } ,
161+ statements : { diff : 10.8 , next : 50.8 , prev : 40 } ,
162+ } )
163+ } )
164+
165+ it ( 'should return new thresholds be a whole number if precision is set to 0' , ( ) => {
166+ const thresholds = {
167+ branches : 10 ,
168+ functions : 20 ,
169+ lines : 30 ,
170+ statements : 40 ,
171+ }
172+ const coverages = {
173+ branches : { pct : 80.6 } ,
174+ functions : { pct : 70.1 } ,
175+ lines : { pct : 60.25 } ,
176+ statements : { pct : 50.89 } ,
177+ }
178+ const margin = 0
179+ const tolerance = 0
180+ const precision = 0
181+
182+ const newThresholds = getNewThresholds (
183+ thresholds ,
184+ coverages ,
185+ margin ,
186+ tolerance ,
187+ precision ,
188+ )
189+
190+ expect ( newThresholds ) . toStrictEqual ( {
191+ branches : { diff : 70 , next : 80 , prev : 10 } ,
192+ functions : { diff : 50 , next : 70 , prev : 20 } ,
193+ lines : { diff : 30 , next : 60 , prev : 30 } ,
194+ statements : { diff : 10 , next : 50 , prev : 40 } ,
195+ } )
196+ } )
0 commit comments