ITADN

[Feature]: jest.retryTimes or at least willRetry in TestResult for custom reporters (again)

#16134Opennemo-cpt 创建于 2026-05-06
:rocket: Feature RequestStale
N
nemo-cptcommented
### 🚀 Feature Proposal There is currently no way to tell by TestResult whether result for the test is final or retry is pending, so there is no way to create custom reporter that may correctly classify test result as _failed_ vs _retrying_ in real time. So I suggest adding this information to the [TestResult](https://github.com/jestjs/jest/blob/main/packages/jest-test-result/src/types.ts#L88-L131) structure either in form of either `retryTimes` number or just `willRetry` flag. ### Motivation We are creating some kind of high-signal real-time test results collecting system, which basically aggregates the testing data and expose it in real time via UI and notifications. Our goal is to provide test failures as quickly as possible for developer to act upon, but the signal should be as reliable as possible. For the jest our only option is some caching logic in reporter with "one try delay" (see example). I believe that just marking result with something indicating that test will be further retried would serve the purpose better and seem to me pretty natural addition (though I am guessing only from user standpoint). ### Why again This was already suggested in https://github.com/jestjs/jest/issues/7906, but original motivation was just to measure flakiness of tests and in this case existing information is definitely enough. But for real-time results classification it is unfortunately not. ### Example ``` class MyReporter { onTestCaseResult(test, tc) { if (tc.willRetry) { this.emitTentative(tc) } else { this.emitFinal(tc) } } // ----- Instead of something like ------ class MyReporter { // delayed results pending = new Map(); // key: testFile + fullName onTestCaseResult(test, tc) { const key = test.path + '::' + tc.fullName; // Send cached on arrival of newer const previous = this.pending.get(key); if (previous) { this.emitTentative(previous); this.pending.delete(key); } if (tc.status === 'passed') { // pass is always final this.emitFinal(tc); } else if (tc.status === 'failed') { // is it final or will retry? Just cache this.pending.set(key, tc); } } onTestResult(test, testResult) { for (const [key, tc] of this.pending) { if (key.startsWith(test.path + '::')) { this.emitFinal(tc); this.pending.delete(key); } } } ```` ### Pitch I believe jest core is the right place for this feature because retryTimes is part of circus. Processing results in close to real time seems to me pretty normal application for custom test reporter and inability to classify results properly is a bit puzzling.
2 条评论