Prompt
How do I parallelize frontend tests to speed up CI
Latest observation
Oct 26, 2026
OpenAI APIWeb search: off
To speed up CI, you can parallelize frontend tests at a few different levels. The best approach depends on your test runner and CI system, but the general idea is:
1) Split tests across CI workers
Run different subsets of tests on multiple machines or jobs at the same time.
Common strategies
- By file: each worker gets a chunk of test files.
- By test duration: distribute longer tests more evenly.
- By historical timing: use past run times to balance shards.
Example approaches
-
Jest
- Use built-in workers on one machine:
jest --maxWorkers=50% - Or split across CI jobs with sharding tools like:
jest --listTests- custom script to partition files
- third-party sharding packages
- Use built-in workers on one machine:
-
Cypress
- Use Cypress Cloud for intelligent load balancing, or manual splitting:
cypress run --spec "cypress/e2e/a.cy.js,cypress/e2e/b.cy.js"
- Use Cypress Cloud for intelligent load balancing, or manual splitting:
-
Playwright
- Built-in sharding:
npx playwright test --shard=1/4 npx playwright test --shard=2/4 - Can also control workers:
npx playwright test --workers=4
- Built-in sharding:
2) Parallelize within the test runner
Most runners already run tests in parallel across CPU cores.
Tune worker count
- Too few workers = underutilized CPU
- Too many workers = overhead, memory pressure, flaky tests
Examples:
- Jest:
--maxWorkers - Playwright:
--workers - Vitest:
--pool/--threadsdepending on version/config
3) Make tests safe to run concurrently
Parallelization only helps if tests don’t interfere with each other.
Watch for:
- Shared test data
- Global browser state
- Reused ports
- Writing to same temp files
- Tests depending on execution order
Fixes
- Use isolated fixtures per test
- Randomize or isolate DB/users/data
- Clean up between tests
- Avoid hardcoded ports; use dynamic ports
- Make tests idempotent
4) Split unit/integration/e2e tests
Don’t run everything the same way.
Typical CI layout
- PR checks: lint + unit tests + a few smoke E2E tests
- Nightly: full integration and full E2E suite
This reduces PR latency while preserving coverage.
5) Cache dependencies and build artifacts
Not parallelization, but often the biggest CI win.
- Cache
node_modules/ package manager cache - Cache browser binaries for Playwright/Cypress
- Cache build output when possible
- Avoid reinstalling dependencies in every job
6) Use test selection
Only run tests affected by the change when appropriate.
- Jest: test impacted files via custom tooling
- Nx/Turborepo: affected commands
- Playwright/Cypress: tag smoke tests, run relevant spec subsets
Recommended CI pattern
A good default setup is:
- Install deps once per job
- Split tests across 2–8 shards
- Run each shard with optimal worker count
- Merge results
- Keep a separate full-suite nightly run
Example with Playwright shards
jobs:
test:
strategy:
matrix:
shard: [1, 2, 3, 4]
steps:
- run: npm ci
- run: npx playwright test --shard=${{ matrix.shard }}/4
Example with Jest parallel workers
jest --maxWorkers=4
If you want, I can show you:
- how to do this for Jest, Vitest, Playwright, or Cypress
- a GitHub Actions example
- a GitLab CI example