Skip to content

Conversation

@MazenSamehR
Copy link

Description

Follow-up to #8812. Align retry types with serialization boundaries, pass TestError directly to retry condition, use SerializableRetry for reporter/runtime-facing data, and sanitize function conditions before reporters. Keeps function conditions usable in test files (workers) while ensuring reporter/config data stays serializable.

Resolves #8482

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

matanshavit and others added 6 commits December 31, 2025 23:17
…nhanced test retry control

This adds three new retry options:
- retryDelay: milliseconds to wait between retry attempts
- retryCondition: string pattern or function to conditionally retry based on error
- retryStrategy: 'immediate' (default), 'test-file', or 'deferred' retry timing
…bject

Refactor retry-related options (retry, retryDelay, retryCondition, retryStrategy)
into a single retry configuration object. This provides a cleaner API where retry
can be either a number (for simple retry count) or an object with count, delay,
condition, and strategy properties.

This change improves type safety and makes the retry configuration more intuitive
while maintaining backward compatibility with numeric retry values.
Group deferred tests by file and setup/cleanup file context before
running retries. This ensures snapshot state is correctly initialized.
Also update file result state after deferred retries complete.
@netlify
Copy link

netlify bot commented Jan 1, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit bd7eaad
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/695faffc616bd600081616bb
😎 Deploy Preview https://deploy-preview-9370--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@MazenSamehR
Copy link
Author

Hi @AriPerkkio, can you please review this PR?

- When a **function**, it receives the error and returns a boolean

> [!WARNING]
When defining `condition` as a function, it must be done in a test file directly, not in `vitest.config.ts` (configurations are serialized for worker threads).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
When defining `condition` as a function, it must be done in a test file directly, not in `vitest.config.ts` (configurations are serialized for worker threads).
::: warning
When defining `condition` as a function, it must be done in a test file directly, not in `vitest.config.ts` (configurations are serialized for worker threads).
:::

const shouldRetry = shouldRetryTest(test, test.result.errors)

if (!shouldRetry) {
// Error doesn't match retry condition, stop retrying
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the AI generated comments that don't explain anything? I feel like they just pollute the code (I would remove most of the non jsdoc comments in this PR)

/**
* Determines if a test should be retried based on its retryCondition configuration
*/
function shouldRetryTest(test: Test, errors: TestError[] | undefined): boolean {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a little bit weird to me because it's applied after the retryCount > retry is checked, so maybe the name should be a bit different? (passesRetryCondition or something) On the !condition line I thought that we always just retry all tests until the pass

const viteConfig = project._vite?.config
const optimizer = config.deps?.optimizer || {}

// Handle retry configuration serialization
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should actually be done in resolveConfig once, not for every serializeConfig call

There should also be a test for this (see failures tests in test/cli)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I'm intentionally passing an invalid condition type (a function) in the config fixture, TypeScript is complaining. Is it ok to add // @ts-expect-error like this:

export default defineConfig({
  test: {
    retry: {
      count: 3,
      // @ts-expect-error
      condition: () => true
    }
  }
})

Or did I misunderstand you?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what you are referring to, I am saying the code from this file should be moved to resolveConfig.ts

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I moved the code to resolveConfig.ts as requested. I'm just creating a test to verify this change as requested.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry. Yes, it is ok to have a ts-expect-error in the test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Enhanced retry options

4 participants