bun test decides which files to run as tests by matching their paths against a set of patterns.
Default Discovery Logic
By default,bun test recursively searches the project directory for files that match these patterns:
*.test.{js|jsx|ts|tsx|mjs|cjs|mts|cts}- Files ending with.test.js,.test.jsx,.test.ts,.test.tsx,.test.mjs,.test.cjs,.test.mts, or.test.cts*_test.{js|jsx|ts|tsx|mjs|cjs|mts|cts}- Files ending with_test.js,_test.jsx,_test.ts,_test.tsx,_test.mjs,_test.cjs,_test.mts, or_test.cts*.spec.{js|jsx|ts|tsx|mjs|cjs|mts|cts}- Files ending with.spec.js,.spec.jsx,.spec.ts,.spec.tsx,.spec.mjs,.spec.cjs,.spec.mts, or.spec.cts*_spec.{js|jsx|ts|tsx|mjs|cjs|mts|cts}- Files ending with_spec.js,_spec.jsx,_spec.ts,_spec.tsx,_spec.mjs,_spec.cjs,_spec.mts, or_spec.cts
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
To filter which test files run, pass 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
bun test matches the pattern against the test name prefixed with the labels of all its parent describe blocks, separated by spaces. For example, a test defined as:
math.test.ts
bun test matches the pattern against the string “Math operations should add correctly”.
Changing the Root Directory
By default, Bun looks for test files starting from the current working directory. Change this with theroot option in bunfig.toml:
bunfig.toml
Execution Order
Tests run in the following order:- Test files run sequentially, or across worker processes with
--parallel - Within each file, tests run sequentially in definition order