# Finding tests (/docs/test/discovery)

<!-- agent-signals: reading_time_min: 2 · est_tokens: 810 · updated: 2026-07-28 -->
Related: [Writing tests](/docs/test/writing-tests.md), [Test configuration](/docs/test/configuration.md), [Runtime behavior](/docs/test/runtime-behavior.md), [Lifecycle hooks](/docs/test/lifecycle.md), [Mocks](/docs/test/mocks.md), [Snapshots](/docs/test/snapshots.md)

`bun test` decides which files to run as tests by matching their paths against a set of patterns.

## Default Discovery Logic [#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 [#exclusions]

By default, `bun test` ignores:

* `node_modules` directories
* Hidden directories (those starting with a period `.`)
* Files that don't have JavaScript-like extensions (based on available [loaders](/bundler/loaders))

## Customizing Test Discovery [#customizing-test-discovery]

### Position Arguments as Filters [#position-arguments-as-filters]

To filter which test files run, pass additional positional arguments to `bun test`:

```bash terminal icon="terminal"
bun test <filter> <filter> ...
```

Any test file with a path that contains one of the filters runs. Filters are substring matches, not glob patterns.

For example, to run all tests in a `utils` directory:

```bash terminal icon="terminal"
bun test utils
```

This matches files like `src/utils/string.test.ts` and `lib/utils/array_test.js`.

### Specifying Exact File Paths [#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:

```bash terminal icon="terminal"
bun test ./test/specific-file.test.ts
```

### Filter by Test Name [#filter-by-test-name]

To filter tests by name rather than file path, use the `-t`/`--test-name-pattern` flag with a regex pattern:

```sh terminal icon="terminal"
# run all tests with "addition" in the name
bun test --test-name-pattern addition
```

The pattern is matched against the test name prefixed with the labels of all its parent `describe` blocks, separated by spaces. For example, a test defined as:

```ts title="math.test.ts" icon="/icons/typescript.svg"
describe("Math", () => {
  describe("operations", () => {
    test("should add correctly", () => {
      // ...
    });
  });
});
```

This test is matched against the string "Math operations should add correctly".

### Changing the Root Directory [#changing-the-root-directory]

By default, Bun looks for test files starting from the current working directory. Change this with the `root` option in `bunfig.toml`:

```toml title="bunfig.toml" icon="settings"
[test]
root = "src"  # Only scan for tests in the src directory
```

## Execution Order [#execution-order]

Tests run in the following order:

1. Test files run sequentially (not in parallel)
2. Within each file, tests run sequentially in definition order
