fix(vitest): prevent negative test durations#9342
Conversation
Failed tests shorter than five milliseconds finished before their start time because the overlap adjustment was not bounded.
Overall package sizeSelf size: 6.74 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.3.1 | 122.62 kB | 438.86 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
🎉 All green!🧪 All tests passed 🔄 Datadog auto-retried 1 job - 1 passed on retry 🎯 Code Coverage (details) 🔗 Commit SHA: 9346ecd | Docs | Datadog PR Page | Give us feedback! |
There was a problem hiding this comment.
More details
The PR fixes a critical bug where failed Vitest tests finishing in under 5ms would produce negative span durations in trace data. The fix adds proper validation (checking for finite, non-negative durations) and clamps the result with Math.max to prevent negatives. New test suite comprehensively covers boundary cases (0–5ms) and invalid inputs. No production code beyond this single location is affected.
📊 Validated against 9 scenarios · Open Bits AI session
🤖 Datadog Autotest · Commit 9346ecd · What is Autotest? · Any feedback? Reach out in #autotest
BenchmarksBenchmark execution time: 2026-07-14 16:49:20 Comparing candidate commit 9346ecd in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 2314 metrics, 44 unstable metrics.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9342 +/- ##
=======================================
Coverage 96.61% 96.61%
=======================================
Files 920 920
Lines 122236 122238 +2
Branches 21070 21078 +8
=======================================
+ Hits 118097 118099 +2
Misses 4139 4139 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
|
||
| const testErrorCh = channel('ci:vitest:test:error') | ||
|
|
||
| describe('VitestPlugin', () => { |
There was a problem hiding this comment.
any way we can keep these in the vitest core integration tests? I'd like to avoid having yet another test file for vitest
There was a problem hiding this comment.
This kind of test is actually more difficult to achieve with an integration test, since the time the test takes is a real time and I am unsure how to write such a test to be deterministic
There was a problem hiding this comment.
I can look into it
|
#9380 should have better coverage than this |
|
Superseded |
Summary
Failed Vitest tests shorter than five milliseconds finished before their start time because the overlap adjustment was not bounded.
Test plan