Skip to main content
Bun’s test runner supports hot reloading with the --watch flag. Tests automatically re-run when source files or test files change.

Basic usage

Enable watch mode:
Bun watches for file changes and re-runs affected tests automatically.

How it works

When a file changes, Bun:
  1. Identifies which test files import the changed file
  2. Re-runs only the affected tests
  3. Displays results immediately
This makes the feedback loop extremely fast.

Watch mode features

Instant feedback

See test results as soon as you save:

Smart test selection

Only affected tests run:

Watch all tests

Re-run all tests on any change:
Press a in watch mode to toggle between affected tests and all tests.

Watch mode commands

Interactive commands in watch mode:
  • Enter - Re-run tests
  • a - Run all tests
  • f - Run only failed tests
  • t - Filter by test name pattern
  • q - Quit watch mode

Filtering in watch mode

Filter by test name

Press t and type a pattern:
Only tests matching “auth” will run.

Run only failed tests

Press f to run only tests that failed:

Watch with other flags

Combine watch mode with other test flags:

Ignoring files

Configure which files to watch in bunfig.toml:

Watch specific files

Watch specific test files:
Watch tests matching a pattern:

Performance tips

Optimize test setup

Minimize expensive setup in test files:

Use lazy imports

Import heavy dependencies lazily:

Exclude slow tests

Skip slow tests in watch mode:
Run with:

Development workflow

Typical TDD workflow with watch mode:
  1. Start watch mode:
  2. Write a failing test
  3. Save the file - test runs automatically and fails
  4. Write implementation code
  5. Save - test runs automatically and passes
  6. Refactor with confidence

CI vs Development

Watch mode is for development only. In CI:

Troubleshooting

Tests not re-running

Ensure files are being watched:

Too many files being watched

Increase file watcher limit on Linux:

Watch mode is slow

  • Reduce the number of test files
  • Optimize beforeAll/beforeEach hooks
  • Use test.concurrent() for parallel execution