Skip to content

Conversation

@Battjmo
Copy link
Contributor

@Battjmo Battjmo commented Aug 19, 2025

close #8424

Description

I've found that when I have the boolean autoUpdate flag enabled and run coverage reports on the same code multiple times, the coverage amounts vary but up to 0.03%. This means code will arbitrarily fail to pass the coverage requirements. Also I don't really care about my coverage percentage being accurate down to two decimal places, which is how V8 reports them.

To address this, I've update the autoUpdate flag to accept either a boolean or a function. If it's a boolean it will keep working as it did before. If it's a function, that function will run on each coverage percentage returned by the engine and return the result, which should be a number or undefined.

So now you can do something like...

// in your vitest.config.mjs
{
"coverage": {
  "thresholds": {
      thresholds: {
        statements: 94,
        branches: 90,
        lines: 94,
        functions: 90,
        autoUpdate: (value) => {
          if (value) {
            // do something to format the value
            return Math.floor(value);
          }
        },
      },
}
}
}

Now when you run test:coverage or whatever your coverage script is, your coverage thresholds will come back rounded down to the nearest whole number.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@netlify
Copy link

netlify bot commented Aug 19, 2025

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 7c4b602
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/68aae13be45ad80008ff0d3c
😎 Deploy Preview https://deploy-preview-8456--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Battjmo Battjmo changed the title feat: update autoUpate to accept function feat: update autoUpdate to accept function Aug 19, 2025
@AriPerkkio AriPerkkio changed the title feat: update autoUpdate to accept function feat(coverage): autoUpdate to support percentage format Aug 20, 2025
@AriPerkkio AriPerkkio changed the title feat(coverage): autoUpdate to support percentage format feat(coverage): autoUpdate to support percentage formatting Aug 20, 2025
@AriPerkkio AriPerkkio force-pushed the autoUpdateFormat branch 2 times, most recently from ce8a7d8 to 9cd0689 Compare August 24, 2025 09:44
Copy link
Member

@AriPerkkio AriPerkkio left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for the feature! 💯

@Battjmo
Copy link
Contributor Author

Battjmo commented Aug 25, 2025

Thanks @AriPerkkio!

@sheremet-va sheremet-va merged commit 99e016b into vitest-dev:main Aug 27, 2025
12 of 14 checks passed
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.

Ability to edit number of decimal places in threshold autoupdtes

3 participants