bun-test
Run JavaScript and TypeScript tests
TLDR
Run all test files found in the project
Run a specific test file or directory
Run tests in "watch" mode (re-runs automatically on file changes)
Run tests and generate a code coverage report
SYNOPSIS
bun test [paths...] [options]
PARAMETERS
--bail
Exit on first test failure
--coverage
Collect and report code coverage
--exact
Disable test name minimization in reports
--filter <regex>
Run tests matching filter regex
--grep <regex>
Run tests whose names match grep regex
--reporter <name>
Use reporter: list, tap, junit, json, etc.
--retries <num>
Retry failed tests this many times
--run-in-band
Run serially, not in parallel
--test-name-pattern <regex>
Run tests matching name pattern regex
--test-timeout <ms>
Timeout individual tests after ms
--throw-on-missing-coverage
Fail if coverage thresholds unmet
--update-snapshots
Update snapshot files
--version
Print bun-test version
--watch
Watch files for changes and re-run
DESCRIPTION
bun test is the built-in test runner for Bun, an all-in-one fast JavaScript runtime, bundler, and package manager. It offers a zero-config, Jest- and Vitest-compatible API for writing unit and integration tests, supporting assertions via expect, test suites with describe and it, hooks like beforeEach, mocking, snapshots, and async testing.
Key advantages include blazing-fast execution (often 10-100x faster than Node.js/Jest due to Bun's Zig-based runtime and JIT), automatic test discovery (files matching *.test.{js,ts,jsx,tsx}, *.spec.{js,ts,jsx,tsx}, or directories named __tests__), parallel execution across cores, and built-in coverage with --coverage using istanbul-compatible reports.
It integrates seamlessly with bun install for dependencies, supports TypeScript out-of-the-box without transpilation, and provides reporters like list (default), tap, junit, and json. Watch mode enables rapid development feedback, and filtering options allow targeted runs. Ideal for modern JS/TS projects seeking simplicity and speed without external test frameworks.
CAVEATS
Requires Bun installed (≥1.0); Node.js/Jest projects need API migration. No native ESM mocking quirks. Coverage requires bun-types for TS accuracy.
TEST DISCOVERY
Auto-runs files: *.test.{js,ts,jsx,tsx}, *.spec.{js,ts,jsx,tsx}, tests/**/*.{js,ts}. Use bun --bun test to force Bun runtime.
CONFIGURATION
Uses bunfig.toml or package.json "bun" section for custom reporters, patterns, timeouts.
HISTORY
Introduced in Bun 0.5.0 (Sep 2023) by Jarred Sumner; rapidly matured with Jest API parity by 1.0 (2024). Focuses on speed via Bun's libuv-free runtime.


