Why jest.retryTimes() is hiding bugs in your test suite
Blog post from Mergify
Jest's retryTimes() function, which re-runs failing tests up to a specified number of times, is critiqued for obscuring underlying issues in test suites by allowing tests to pass despite intermittent failures. This approach can lead to production bugs going unnoticed during continuous integration (CI) processes, as it discards initial failures and reports only the final result. RetryTimes() treats diverse issues such as genuine bugs, test pollution, environment instability, and non-deterministic tests uniformly, which often results in obscuring rather than addressing underlying problems. While some argue that retryTimes is useful due to limited engineering resources, it can diminish the urgency to fix underlying test issues, leading to long-term maintenance challenges. The article suggests a more effective approach involves using flaky-test detection tools that record test outcomes, quarantine problematic tests, and provide visibility into test stability without discarding initial failures. RetryTimes is deemed acceptable only in specific situations, such as actively triaging a known issue or dealing with unavoidable external-service flakiness, and the piece encourages teams to remove unnecessary retryTimes configurations to expose and address real bugs.