Linux command
bun-test 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Run all tests
bun test
Run tests in specific file
bun test [path/to/test.ts]
Run tests matching pattern
bun test --test-name-pattern "[pattern]"
Run tests in watch mode
bun test --watch
Update snapshots
bun test --update-snapshots
Run with coverage
bun test --coverage
Output JUnit XML report
bun test --reporter=junit --reporter-outfile=[results.xml]
Run with timeout
bun test --timeout [5000]
说明
bun test is Bun's built-in test runner with a Jest-compatible API. It provides TypeScript and JSX support, snapshot testing, mocks, lifecycle hooks, and watch mode out of the box. Tests execute with the Bun runtime, providing significantly improved performance over traditional JavaScript test runners.
参数
- --watch
- Re-run tests on file changes
- --update-snapshots
- Update snapshot files
- --coverage
- Enable code coverage reporting
- --test-name-pattern _pattern_
- Only run tests matching pattern
- --timeout _ms_
- Test timeout in milliseconds
- --reporter _type_
- Output format (default, junit, etc.)
- --reporter-outfile _file_
- Write reporter output to file
- --bail _n_
- Stop after n test failures
- --rerun-each _n_
- Run each test n times.
- --preload _module_
- Preload a module before tests run.
- --only
- Only run tests marked with `test.only`.
FAQ
What is the bun-test command used for?
bun test is Bun's built-in test runner with a Jest-compatible API. It provides TypeScript and JSX support, snapshot testing, mocks, lifecycle hooks, and watch mode out of the box. Tests execute with the Bun runtime, providing significantly improved performance over traditional JavaScript test runners.
How do I run a basic bun-test example?
Run `bun test` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --watch do in bun-test?
Re-run tests on file changes