Skip to content

Feature Request: Enhanced retry options #8482

@matzeeable

Description

@matzeeable

Clear and concise description of the problem

Vitest supports a retry mechanism, but currently it only retries a fixed number of times on any kind of error.

This limits flexibility in several ways:

  • It’s not possible to retry only on specific error types (e.g. TimeoutError).
  • There is no option to delay retries (useful for APIs, DBs, or rate-limited services).
  • There is no option to defer retries until the end of the test file, which can improve flow and reduce interference with other tests.

Other test runners (e.g. Jest, WebdriverIO) provide these options:

Suggested solution

Extend the retry API with the following features:

  • retryStrategy: "immediate" | "test-file" | "deferred" (default immediate)

    • immediate: retry failed test immediately.
    • test-file: run retries until the end of the test file.
    • deferred: defer retries after all other tests have run across all test files.
  • retryDelay: number (milliseconds, default 0). Or even better, use Add Support for Backoff Mechanism in Retry Configuration #8095

  • retryCondition: string | ((error: Error) => boolean): If string (Regexp), it should only retry when the occurred Error message matches the Regexp. If function, it should only retry when the function returns true.

Alternative

No response

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomersp2-nice-to-haveNot breaking anything but nice to have (priority)

    Projects

    Status

    Approved

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions