Skip to content
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

Support for non-global code coverage thresholds #18

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

thall90
Copy link

@thall90 thall90 commented May 17, 2023

This PR adds support for non-global code coverage thresholds in the form of threshold-keys, which should resolve #13.

@codecov-commenter
Copy link

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (66018e5) 100.00% compared to head (1f32256) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##            master       #18   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            7         7           
  Lines           69        81   +12     
=========================================
+ Hits            69        81   +12     
Impacted Files Coverage Δ
lib/getChanges.js 100.00% <100.00%> (ø)
lib/getData.js 100.00% <100.00%> (ø)
lib/getNewThresholds.js 100.00% <100.00%> (ø)
lib/index.js 100.00% <100.00%> (ø)
lib/outputChanges.js 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Owner

@rbardini rbardini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, @thall90! Added some questions/suggestions.

In addition, I wonder if updating all declared threshold paths in the config file—instead of only global or those explicitly defined—would be a better default. What do you think?

@@ -66,9 +72,17 @@ Options:
-c, --config <path> path to a Jest config file (default: 'jest.config.js')
-m, --margin <margin> minimum threshold increase (default: 0)
-t, --tolerance <tolerance> threshold difference from actual coverage
-k, --thresholdKeys <keys> comma-separated list of threshold keys to consider (default: 'global')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jest calls these "paths", I think we should do the same for consistency. Also, we should probably use a variadic option:

Suggested change
-k, --thresholdKeys <keys> comma-separated list of threshold keys to consider (default: 'global')
-p, --threshold-path <paths...> comma-separated list of threshold keys to consider (default: 'global')

Object.entries(newValues).forEach(([type, { prev, next, diff }]) => {
const regex = new RegExp(
`(?<=${keyPrefix}${thresholdKey}:\\s*{[^}]*${type}:\\s*)\\d*\\.?\\d+(?=,\\s*\\n\\s*${
type === 'statements' ? '}' : ''
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we safely assume that statements always comes last?


it('returns changes for an updated custom threshold', () => {
fs.readFileSync.mockReturnValue(`
module.exports = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the getContents helper with level2 = './src/modules/**/*.module.ts' to generate this mock data.

@vvscode
Copy link

vvscode commented Nov 8, 2023

@thall90 are you going to complete it?

@thall90
Copy link
Author

thall90 commented Nov 24, 2023

@rbardini @jimmywarting @vvscode I apologize for the delay - life's been busy, to say the least.

@rbardini I agree that bumping up coverage for all threshold paths by default makes sense. I'll have that change along with all of the requested changes pushed tomorrow 👍

@thall90
Copy link
Author

thall90 commented Nov 26, 2023

@rbardini While wrapping up changes to this PR, I found what appears to be a pretty big miss in my original changes:

In getNewThresholds we're using the total value from the coverage-summary.json for both global and non-global coverage threshold paths, which doesn't seem right, since Jest only checks coverage for files that match glob provided in the threshold path in non-global cases.

My belief is that we will need to implement similar functionality to Jest's coverage threshold checking in order to verify whether a given threshold path's values should be bumped, since Jest doesn't appear to expose the result of their threshold checks.

Happy to move forward with implementing these changes as well, but I wanted to get your take on the problem and the approach first.

Thanks in advance!

@vvscode
Copy link

vvscode commented Nov 26, 2023

I just implemented some workaround script for my project and it works in a way

  1. take config
  2. put 100% coverage limit for all non-global items
  3. run tests
  4. analyze output (jest says for every line, that doesn't satisfy expectations what's the current coverage)
  5. update config with received data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support non-global coverageThreshold
4 participants