Skip to content

fix: distribute test files to shards more evenly #8288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 12, 2025

Conversation

Shinyaigeek
Copy link
Contributor

@Shinyaigeek Shinyaigeek commented Jul 10, 2025

Description

Fixes: #8244

In current implementation, test files are distributed with Math.ceil(files.length / count) in {index}/{count} shard setting.
This causes #8244 because this ceil based distribution logic can consume all test files by shards without the ending shard.
In addition to this, I believe this logic causes a bit lower performance in an edge-case like:

  • test files: 10
  • --shard index/3

In the above case, test files will be distributed as [3, 3, 3, 1] but I think it is more ideal to be distributed as [3, 3, 2, 2] in the point of parallelism.

This PR fixes this issue by introducing distribution logic based on Math.floor(files.length / count) instead of Math.ceil

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.

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:.

@Shinyaigeek Shinyaigeek changed the title Distribute test files to shards more evenly fix: distribute test files to shards more evenly Jul 10, 2025
Copy link

netlify bot commented Jul 10, 2025

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 461e676
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/686fc087c4180100089bac05
😎 Deploy Preview https://deploy-preview-8288--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.

Copy link
Member

@AriPerkkio AriPerkkio left a comment

Choose a reason for hiding this comment

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

Looks good, thanks @Shinyaigeek! 💯

@AriPerkkio AriPerkkio merged commit 7b48995 into vitest-dev:main Jul 12, 2025
14 of 15 checks passed
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.

No test files found error with sharing and just a few shards
2 participants