You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
coverage.thresholds.autoUpdate: pass previous threshold as second argument #10459
As a developer using Vitest I want coverage.thresholds.autoUpdate to receive
the previous threshold as a second argument so that I can tell apart V8 variance
from a real regression.
The current callback signature is (newValue: number) => number. Without the
old value there is no way to write logic like "only accept a drop of max X%"
Suggested solution
Pass the current (pre-update) threshold as a second argument to the autoUpdate
callback. The value is already in scope inside updateThresholds as thresholds[key] — it just isn't forwarded to the formatter. The change is a single line and fully backwards-compatible (existing single-arg callbacks continue to work).
In my experience V8's native coverage can produce slightly different numbers between runs, which is why a fixed buffer feels necessary. Is this something others run into too? We would love to hear what buffer values people are using in practice.
I looked at the source and the change appears small enough that we would be happy to open a PR if the maintainers agree with the direction. The old threshold is already in scope when thresholdsToUpdate is built — it just needs to be
carried through to the formatter call, and the autoUpdate type signature updated to (newValue: number, oldValue: number) => number.
Is that the right approach?
In my experience V8's native coverage can produce slightly different numbers between runs, which is why a fixed buffer feels necessary.
[...]
Is that the right approach?
We haven't seen reports about this before. Sounds like bug. Fixing it with new feature doesn't sound like the right approach.
I would recommend to open bug report with minimal reproduction so that the root cause can be fixed properly.
@AriPerkkio thanks for the response. I did some further digging and the root cause for the V8 variance was elsewhere. My apologies for this "false bug report".
Having the previous threshold as a second argument could still be a nice improvement, but I also understand that this issue is closed for now.
Sure, I don't have any strong opinions against the idea of passing the old value as second argument. I would imagine someone could use it to log messages like Updated threshold from x to y.
I haven't contributed to Vitest before, but I'd be happy to give it a shot and submit a pull request for this feature.
Would that be a good way to move forward?
Activity
AriPerkkio commentedon May 26, 2026
We haven't seen reports about this before. Sounds like bug. Fixing it with new feature doesn't sound like the right approach.
I would recommend to open bug report with minimal reproduction so that the root cause can be fixed properly.
wouterkroes commentedon Jun 1, 2026
@AriPerkkio thanks for the response. I did some further digging and the root cause for the V8 variance was elsewhere. My apologies for this "false bug report".
Having the previous threshold as a second argument could still be a nice improvement, but I also understand that this issue is closed for now.
AriPerkkio commentedon Jun 1, 2026
Sure, I don't have any strong opinions against the idea of passing the old value as second argument. I would imagine someone could use it to log messages like
Updated threshold from x to y.wouterkroes commentedon Jun 1, 2026
I haven't contributed to Vitest before, but I'd be happy to give it a shot and submit a pull request for this feature.
Would that be a good way to move forward?
AriPerkkio commentedon Jun 1, 2026
Sounds good! The fix should be done somewhere around here:
vitest/packages/vitest/src/node/coverage.ts
Lines 635 to 638 in fe5ed6b
And a test to verify it could be something similar to this:
vitest/test/coverage-test/test/threshold-auto-update.unit.test.ts
Lines 133 to 157 in fe5ed6b
wouterkroes commentedon Jun 1, 2026
@AriPerkkio #10495 what do you think of the fix?