Skip to content

coverage.thresholdAutoUpdate does not work when starting from zero #4286

@krystian-lieber

Description

@krystian-lieber

Describe the bug

for (const key of THRESHOLD_KEYS) {
const threshold = thresholds[key] || 100
const actual = Math.min(...summaries.map(summary => summary[key].pct))
if (actual > threshold)
thresholdsToUpdate.push([key, actual])
}

thresholds hold the current configuration for the limits; if it is set to zero, then thresholds[key] || 100 evaluates to 100.
As I understand, the logic here is not to update when the value was not set in the configuration in the first place.
?? should be used instead of || as only undefined should become 100, and 0 should stay 0.

Reproduction

This is easy enough to understand without a reproduction repository.
Simple test on playcode https://playcode.io/1624061

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700KF
    Memory: 52.94 GB / 95.86 GB
  Binaries:
    Node: 20.8.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.5 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 10.1.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 117.0.5938.134
    Edge: Spartan (44.22621.2283.0), Chromium (117.0.2045.60)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    @vitest/coverage-v8: ^0.34.1 => 0.34.1
    @vitest/ui: ^0.34.5 => 0.34.5
    vitest: ^0.34.1 => 0.34.1

Used Package Manager

yarn

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: coverageIssues and PRs related to the coverage feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions