-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(precision): add -p, --precision
option
#20
Conversation
… can increase the coverage by a whole number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @saunders1989! Left a couple comments.
Also, please remember to update the README with the new option. You can run jest-it-up --help
and copy-paste the output.
bin/jest-it-up
Outdated
.option( | ||
'-w, --whole-number', | ||
'round coverage thresholds down to whole a whole number', | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, but I think we could have a more generic solution:
.option( | |
'-w, --whole-number', | |
'round coverage thresholds down to whole a whole number', | |
) | |
.option('-p, --precision <digits>', | |
'number of threshold decimal places to persist', | |
parseInt, | |
2, | |
) |
You can then do +desiredCoverage.toFixed(precision)
in getNewThresholds
, and pass --precision 0
if you want whole numbers. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of what you have proposed however i just found out that if the coverage is 30.6, and we want precision 0 it will then round up to 31. technically the coverage isnt at 31 so would fail i think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, I forgot toFixed()
rounds the number. In that case we would need something like this:
const factor = Math.pow(10, precision)
Math.trunc(desiredCoverage * factor) / factor
It may still round numbers due to floating point arithmetic though (e.g. 4.27
with precision 2
→ 4.26
), but I think that's acceptable, especially since it's opt-in. Alternatively, we could manipulate the number as a string, but that can get ugly pretty quickly.
lib/getNewThresholds.js
Outdated
@@ -9,7 +9,7 @@ const getNewThresholds = (thresholds, coverages, margin, tolerance) => | |||
if (desiredCoverage >= threshold + margin) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should calculate the rounded/truncated desiredCoverage
value before this condition, otherwise we may end up updating the number to the same value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im not quite following what you mean about calculating the number first. could you just explain in a bit more detail please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may need to calculate the final desiredCoverage
value (accounting for the truncation) before entering this if
block.
Let's say desiredCoverage == 50.25
, threshold == 50.2
, margin == 0
. Assuming we support custom precision, and it's 1
in this case, we actually don't need to update coverage thresholds, because the new value would be the same as the current one: 50.2
.
So the math you do below must be done earlier, likely together with tolerance
:
const desiredCoverage = Math.trunc((coverage - tolerance) * factor) / factor
In fact, we should probably replace the >=
with >
as well to avoid a 0
bump, but that can be left to a separate PR.
@rbardini Hey thanks for the speedy comments back. I've tried to implement what you've talked about. let me know what you'd like changing :) |
Wondering if you'd had a chance to look at this @rbardini since the changes were made? Would love to have this rounding stuff available in a couple of projects 🙏🏻 |
Sorry for the delay, folks! LGTM, but @saunders1989 would you mind having a look, please? Some |
@rbardini sorry about that. obviously didn't run all the tests locally 🤦. i have fixed and updated them so should be good now. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #20 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 7 7
Lines 69 71 +2
=========================================
+ Hits 69 71 +2 ☔ View full report in Codecov by Sentry. |
-p, --precision
option
Awesome, thanks @saunders1989! |
🎉 This PR is included in version 3.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
We have an issue where we want to bump the coverage but don't want to bump it by 2 decimal places. We want to bump it by a whole number. so if our margin is 1 and the increase is 1.65% we want to go from 40 -> 41 instead of 41.65.
I think this also addresses the issues been spoken about here - #17
Also please feel free to rip this apart and tell me if you'd like changes. it would be great to get this in :)