concurrentTestGlob option in bunfig.toml runs tests concurrently in files whose names match a glob pattern.
Project Structure
Project Structure
Configuration
Configure yourbunfig.toml to run test files with the “concurrent-” prefix concurrently:
bunfig.toml
Test Files
Unit Test (Sequential)
Tests that share state or depend on ordering should stay sequential:Integration Test (Concurrent)
Tests in files matching the glob pattern automatically run concurrently:Running Tests
terminal
Benefits
- Gradual migration: rename files one at a time to move them to concurrent execution
- Clear organization: the filename tells you how a file’s tests run
- Performance: independent integration tests finish faster in parallel
- Safety: unit tests stay sequential where they need to
Migration Strategy
To migrate existing tests to concurrent execution:- Start with independent integration tests - these typically don’t share state
- Rename files to match the glob pattern:
mv api.test.ts concurrent-api.test.ts - Run
bun test- check for race conditions and flaky or unexpected failures - Continue migrating stable tests file by file
Tips
- Use descriptive prefixes:
concurrent-,parallel-,async- - Keep related sequential tests together in the same directory
- Document why certain tests must remain sequential with comments
- Use
test.concurrent()for fine-grained control in sequential files (in files matched byconcurrentTestGlob, plaintest()already runs concurrently)
Multiple Patterns
concurrentTestGlob also accepts multiple patterns:
bunfig.toml
- All tests in
integration/directories - All tests in
e2e/directories - All tests with
concurrent-prefix anywhere in the project