Skip to main content
The concurrentTestGlob option in bunfig.toml runs tests concurrently in files whose names match a glob pattern.

Project Structure

Project Structure

Configuration

Configure your bunfig.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:
tests/unit/math.test.ts

Integration Test (Concurrent)

Tests in files matching the glob pattern automatically run concurrently:
tests/integration/concurrent-api.test.ts

Running Tests

terminal

Benefits

  1. Gradual migration: rename files one at a time to move them to concurrent execution
  2. Clear organization: the filename tells you how a file’s tests run
  3. Performance: independent integration tests finish faster in parallel
  4. Safety: unit tests stay sequential where they need to

Migration Strategy

To migrate existing tests to concurrent execution:
  1. Start with independent integration tests - these typically don’t share state
  2. Rename files to match the glob pattern: mv api.test.ts concurrent-api.test.ts
  3. Run bun test - check for race conditions and flaky or unexpected failures
  4. 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 by concurrentTestGlob, plain test() already runs concurrently)

Multiple Patterns

concurrentTestGlob also accepts multiple patterns:
bunfig.toml
Tests in files matching any of these patterns run concurrently:
  • All tests in integration/ directories
  • All tests in e2e/ directories
  • All tests with concurrent- prefix anywhere in the project