LinuxCommandLibrary

bun-test

Built-in Jest-compatible test runner

TLDR

Run all tests

$ bun test
copy
Run tests in specific file
$ bun test [path/to/test.ts]
copy
Run tests matching pattern
$ bun test --test-name-pattern "[pattern]"
copy
Run tests in watch mode
$ bun test --watch
copy
Update snapshots
$ bun test --update-snapshots
copy
Run with coverage
$ bun test --coverage
copy
Output JUnit XML report
$ bun test --reporter=junit --reporter-outfile=[results.xml]
copy
Run with timeout
$ bun test --timeout [5000]
copy

SYNOPSIS

bun test [options] [files]

DESCRIPTION

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.

PARAMETERS

--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

TEST FILE PATTERNS

The test runner searches for files matching:
- *.test.{js,jsx,ts,tsx}
- *_test.{js,jsx,ts,tsx}
- *.spec.{js,jsx,ts,tsx}
- *_spec.{js,jsx,ts,tsx}

API

Tests use describe, test/it, expect, beforeAll, beforeEach, afterEach, afterAll, and mock functions from bun:test module.

CAVEATS

While aiming for Jest compatibility, not all Jest features are implemented. GitHub Actions annotations are automatically enabled when running in CI. Some Jest-specific plugins may not work.

SEE ALSO

bun(1), bun-run(1), jest(1), vitest(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community