Polyscope - The agent-first dev environment for Laravel

Time-Based Sharding in Pest v4.6.0

Published on by

Time-Based Sharding in Pest v4.6.0 image

Pest v4.6.0 adds time-based shard distribution, a new mode that balances CI shards by actual test execution time rather than file count. If you're already using --shard in CI, recording timing data with --update-shards and committing the resulting JSON file is all that's needed to switch those jobs to time-balanced distribution.

  • Time-based shard distribution via --update-shards
  • Timing data stored in tests/.pest/shards.json

What's New

Time-Based Sharding

When running tests in parallel across multiple CI shards, splitting by file count can produce uneven jobs — one shard finishes in seconds while another takes several minutes. Pest v4.6.0 addresses this with time-balanced sharding.

Step 1: Run the full test suite with --update-shards to record per-class timing data:

./vendor/bin/pest --update-shards

You can combine this with --parallel to speed up the timing run:

./vendor/bin/pest --parallel --update-shards

This writes each test class's duration to tests/.pest/shards.json:

{
"timings": {
"Tests\\Feature\\Payments\\StripeCheckoutTest": 1.608,
"Tests\\Feature\\Reports\\SalesReportTest": 2.105,
"Tests\\Unit\\Models\\UserTest": 0.050
},
"checksum": "...",
"updated_at": "2026-04-14T10:30:00+00:00"
}

Step 2: Commit tests/.pest/shards.json to your repository.

Step 3: Run sharded CI jobs as usual. When the timing file is present, Pest automatically uses time-balanced distribution:

./vendor/bin/pest --shard=1/5

The output confirms time-balanced sharding is active:

Shard: 1 of 5 — 12 files ran, out of 50 (time-balanced).

When test files are added or renamed after the timing file was last generated, Pest detects the staleness and displays a warning:

WARN The [tests/.pest/shards.json] file is out of date...

Tests still run: new files are distributed evenly across shards while known files remain time-balanced. Deleting test files does not trigger the warning, and stale timing entries are ignored until you regenerate the file.

A GitHub Actions matrix setup looks like this:

strategy:
matrix:
shard: [1, 2, 3, 4, 5]
 
steps:
- name: Run tests
run: ./vendor/bin/pest --shard=${{ matrix.shard }}/5

PR: #1671, contributed by @nunomaduro

References

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
Acquaint Softtech

Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Visit Acquaint Softtech
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
MongoDB logo

MongoDB

Enhance your PHP applications with the powerful integration of MongoDB and Laravel, empowering developers to build applications with ease and efficiency. Support transactional, search, analytics and mobile use cases while using the familiar Eloquent APIs. Discover how MongoDB's flexible, modern database can transform your Laravel applications.

MongoDB

The latest

View all →
Flaky Test Retries in Pest v4.5.0 image

Flaky Test Retries in Pest v4.5.0

Read article
Debugging production Laravel apps without losing your mind image

Debugging production Laravel apps without losing your mind

Read article
Passage: A Lightweight API Proxy Gateway for Laravel image

Passage: A Lightweight API Proxy Gateway for Laravel

Read article
PestPHP Intellisense in Laravel VS Code Extension v1.7.0 image

PestPHP Intellisense in Laravel VS Code Extension v1.7.0

Read article
Drop in comments for Filament with Commentions image

Drop in comments for Filament with Commentions

Read article
Laravel Starter Kits Now Include Toast Notifications image

Laravel Starter Kits Now Include Toast Notifications

Read article