[test optimization] Fix EFD retries in jest#7637
Conversation
Overall package sizeSelf size: 4.87 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 2.0.6 | 81.92 kB | 816.75 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7637 +/- ##
==========================================
+ Coverage 80.27% 80.29% +0.02%
==========================================
Files 734 738 +4
Lines 31644 31897 +253
==========================================
+ Hits 25401 25611 +210
- Misses 6243 6286 +43 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This comment has been minimized.
This comment has been minimized.
BenchmarksBenchmark execution time: 2026-03-03 12:32:28 Comparing candidate commit 27dbad3 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 231 metrics, 29 unstable metrics. |
jest
E2E Test Report: SUCCESS ✅Tested by: Shepherd Agent (autonomous QA for Datadog Test Optimization) Test Environment
Results
Issues Found & ResolvedAn earlier commit on this branch (before "fix logic") was broken on Jest 27.5.1:
The "fix logic" commit resolves this by temporarily setting Test Methodology
This E2E test was performed by Shepherd — autonomous QA agent for Datadog Test Optimization |
What does this PR do?
Implements duration-based retry count selection for Early Flake Detection (EFD) in Jest. Instead of
retrying every new test a fixed number of times, the retry count is now chosen from the
slow_test_retriesbucket map returned by the backend (5s,10s,30s,5m), based on howlong the test's first execution took. Tests that exceed 5 minutes are tagged as slow and not
retried at all.
Motivation
The backend already returns a
slow_test_retriesmap as part of the library configuration, butit was being ignored — Jest always used a single fixed retry count. This PR wires up the correct
per-duration retry counts.
Additional Notes
Because the duration is only known after the first execution, retry scheduling was moved from the
add_testevent (collection phase) totest_done(execution phase). This required a workaroundfor jest-circus's internal guards:
state.currentDescribeBlockpoints to the ROOT block,whose tests loop has already finished. Retries added there would never run. Fix: temporarily set
state.currentDescribeBlock = event.test.parentso retries land in the still-iterating childrenarray.
state.hasStarted = truecausestest()to throw"Cannot add a test after tests have started running". Fix: temporarily setstate.hasStarted = falsewhilescheduling retries.
Both state fields are restored immediately after
retryTest()returns. All [email protected] andjest@latest integration tests pass.