Default Discovery Logic
By default,bun test recursively searches the project directory for files that match specific patterns:
*.test.{js|jsx|ts|tsx}- Files ending with.test.js,.test.jsx,.test.ts, or.test.tsx*_test.{js|jsx|ts|tsx}- Files ending with_test.js,_test.jsx,_test.ts, or_test.tsx*.spec.{js|jsx|ts|tsx}- Files ending with.spec.js,.spec.jsx,.spec.ts, or.spec.tsx*_spec.{js|jsx|ts|tsx}- Files ending with_spec.js,_spec.jsx,_spec.ts, or_spec.tsx
Exclusions
By default, Bun test ignores:node_modulesdirectories- Hidden directories (those starting with a period
.) - Files that don’t have JavaScript-like extensions (based on available loaders)
Customizing Test Discovery
Position Arguments as Filters
You can filter which test files run by passing additional positional arguments tobun test:
terminal
utils directory:
terminal
src/utils/string.test.ts and lib/utils/array_test.js.
Specifying Exact File Paths
To run a specific file in the test runner, make sure the path starts with./ or / to distinguish it from a filter name:
terminal
Filter by Test Name
To filter tests by name rather than file path, use the-t/--test-name-pattern flag with a regex pattern:
terminal
Changing the Root Directory
By default, Bun looks for test files starting from the current working directory. You can change this with theroot option in your bunfig.toml:
bunfig.toml
Execution Order
Tests are run in the following order:- Test files are executed sequentially (not in parallel)
- Within each file, tests run sequentially based on their definition order