concurrentTestGlob option to selectively run tests concurrently based on file naming patterns.
Project Structure
Project Structure
Configuration
Configure yourbunfig.toml to run test files with “concurrent-” prefix concurrently:
bunfig.toml
Test Files
Unit Test (Sequential)
Sequential tests are good for tests that share state or have specific ordering requirements:Integration Test (Concurrent)
Tests in files matching the glob pattern automatically run concurrently:Running Tests
terminal
Benefits
- Gradual Migration: Migrate to concurrent tests file by file by renaming them
- Clear Organization: File naming convention indicates execution mode
- Performance: Integration tests run faster in parallel
- Safety: Unit tests remain sequential where needed
- Flexibility: Easy to change execution mode by renaming files
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 - Verify tests still pass - Run
bun testto ensure no race conditions - Monitor for shared state issues - Watch for flaky tests or unexpected failures
- Continue migrating stable tests incrementally - Don’t rush the migration
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 (Note: In files matched byconcurrentTestGlob, plaintest()already runs concurrently)
Multiple Patterns
You can specify multiple patterns for different test categories:bunfig.toml
- All tests in
integration/directories - All tests in
e2e/directories - All tests with
concurrent-prefix anywhere in the project