Meta tags:
description= Bun s fast, built-in, Jest-compatible test runner with TypeScript support, lifecycle hooks, mocking, and watch mode;
Headings (most frequently used words):
test, execution, tests, concurrent, testing, integration, order, bail, with, reporting, github, actions, flag, runner, cli, usage, documentation, index, on, this, page, run, ci, cd, timeouts, retry, failed, rerun, randomize, out, watch, mode, lifecycle, hooks, mocks, snapshot, ui, dom, performance, ai, agent, examples, getting, started, features, specialized, junit, xml, reports, gitlab, etc, max, concurrency, serial, reproducible, random, seed, environment, variables, behavior, control, filtering, coverage, snapshots, how, to, install, bun, in, workflow,
Text of the page (most frequently used words):
test (149), bun (61), the (59), tests (44), run (29), with (29), concurrent (23), terminal (21), flag (21), expect (19), and (16), all (16), name (15), #random (15), retry (15), default (14), number (14), use (14), this (13), for (13), reporter (13), runner (13), testing (13), runs (12), coverage (11), seed (11), order (11), each (11), files (10), file (10), bail (10), execution (10), github (9), math (9), snapshots (8), output (8), junit (8), randomize (8), when (8), from (8), lifecycle (8), watch (8), tobe (8), actions (8), failures (7), you (7), see (7), import (7), jest (7), hooks (7), serial (7), snapshot (6), boolean (6), that (6), are (6), after (6), times (6), dom (6), mock (6), value (6), true (6), xml (6), install (6), page (5), pattern (5), update (5), string (5), max (5), concurrency (5), set (5), failed (5), rerun (5), timeout (5), agent (5), following (5), can (5), sharedstate (5), jsx (5), documentation (4), enable (4), dots (4), path (4), outfile (4), reporting (4), given (4), not (4), specify (4), per (4), 5000 (4), usage (4), but (4), code (4), environment (4), integration (4), mocks (4), const (4), preload (4), mode (4), uses (4), running (4), workflow (4), tsx (4), built (3), writing (3), only (3), directory (3), defaults (3), report (3), text (3), format (3), marked (3), todo (3), once (3), randomization (3), control (3), summary (3), passing (3), behavior (3), variables (3), failure (3), fast (3), compatible (3), supports (3), before (3), reports (3), out (3), same (3), pass (3), global (3), input (3), concurrently (3), enabled (3), sequentially (3), api (3), fetch (3), async (3), parallel (3), filter (3), typescript (3), runtime (3), getting (3), started (3), issue (2), baz (2), bar (2), foo (2), examples (2), alias (2), available (2), console (2), matches (2), filtering (2), maximum (2), exit (2), milliseconds (2), cli (2), still (2), claudecode (2), example (2), claude (2), displayed (2), any (2), performance (2), library (2), popular (2), tomatchsnapshot (2), val (2), setup (2), inside (2), like (2), reproduce (2), previous (2), reproducible (2), fail (2), used (2), helps (2), non (2), bunfig (2), toml (2), overrides (2), automatically (2), fails (2), then (2), qualifiers (2), independent (2), these (2), even (2), await (2), other (2), within (2), suites (2), timeouts (2), writes (2), gitlab (2), etc (2), dependencies (2), checkout (2), build (2), how (2), configuration (2), specific (2), addition (2), filte (2), filters (2), patterns (2), compatibility (2), support (2), features (2), copy (2), search (2), index (2), hosted, mintlify, developer, platform, powered, youtube, discord, next, raise, suggest, edits, yes, was, helpful, including, whose, includes, dir, lcov, generate, profile, shorthand, required, requires, regex, include, execute, suite, treat, overridden, help, catch, certain, bugs, shows, hides, verbose, quiet, statistics, remain, intact, skipped, indicators, hidden, detail, detected, generic, replit, repl_id, friendly, coding, assistant, quieter, keeps, details, drops, rest, noise, react, happydom, libraries, alternatively, behaves, identically, tohavebeencalledtimes, tohavebeencalled, tobegreaterthan, create, functions, function, define, separate, preloaded, afterall, aftereach, beforeeach, beforeall, description, hook, accepts, changes, abort, preferable, stop, early, reduce, cpu, implies, don, need, both, always, produces, 123456, randomized, debugging, dependent, ran, across, 00ms, 12345, detect, depend, shared, state, 100, multiple, surfaces, flaky, deterministic, also, custom, its, own, passes, subsequent, attempt, reported, expected, chained, failing, chaining, depends, second, first, must, let, force, sequential, endpoint2, endpoint1, mark, individual, prevent, resource, exhaustion, many, limit, simultaneously, unless, their, respective, which, speeds, results, pipelines, stdout, stderr, usual, end, write, together, npm, yarn, pnpm, instead, prefer, assuming, your, project, has, oven, steps, ubuntu, latest, app, jobs, workflows, yml, add, step, needed, than, installing, detects, emits, annotations, directly, variety, integrations, single, process, loads, scripts, exits, zero, make, sure, starts, distinguish, additional, positional, arguments, one, commonly, names, glob, yet, supported, _spec, spec, _test, recursively, searches, working, match, written, javascript, aims, everything, implemented, track, tracking, script, pre, loading, ships, mocking, reporters, specialized, dates, finding, feedback, blog, reference, guides, bundler, package, manager, navigation, home, skip, main, content, discover, pages, exploring, further, complete, docs, llms, txt,
Text of the page (random words):
test runner bun documentation index fetch the complete documentation index at docs llms txt use this file to discover all available pages before exploring further skip to main content bun home page search k install bun search navigation getting started test runner runtime package manager bundler test runner guides reference blog feedback getting started test runner writing tests test configuration test execution runtime behavior finding tests test features lifecycle hooks mocks snapshots dates and times specialized testing dom testing reporting code coverage test reporters on this page run tests ci cd integration github actions how to install bun in a github actions workflow junit xml reports gitlab etc timeouts concurrent test execution concurrent flag max concurrency flag test concurrent test serial retry failed tests rerun tests randomize test execution order reproducible random order with seed bail out with bail watch mode lifecycle hooks mocks snapshot testing ui dom testing performance ai agent integration environment variables behavior cli usage execution control test filtering reporting coverage snapshots examples getting started test runner copy page bun s fast built in jest compatible test runner with typescript support lifecycle hooks mocking and watch mode copy page bun ships with a fast built in jest compatible test runner tests run in the bun runtime and support the following features typescript and jsx lifecycle hooks snapshot testing ui dom testing watch mode with watch script pre loading with preload bun aims for compatibility with jest but not everything is implemented to track compatibility see this tracking issue run tests terminal bun test tests are written in javascript or typescript with a jest like api see writing tests math test ts import expect test from bun test test 2 2 expect 2 2 tobe 4 the runner recursively searches the working directory for files that match the following patterns test js jsx ts tsx _test js jsx ts tsx spec js jsx ts tsx _spec js jsx ts tsx to filter the set of test files to run pass additional positional arguments to bun test any test file with a path that matches one of the filters runs filters are commonly file or directory names glob patterns are not yet supported terminal bun test filte r filte r to filter by test name use the t test name pattern flag terminal run all tests or test suites with addition in the name bun test test name pattern addition to run a specific file in the test runner make sure the path starts with or to distinguish it from a filter name terminal bun test test specific file test ts the test runner runs all tests in a single process it loads all preload scripts see lifecycle then runs all tests if a test fails the test runner exits with a non zero exit code ci cd integration bun test supports a variety of ci cd integrations github actions bun test automatically detects when it s running inside github actions and emits github actions annotations to the console directly no configuration is needed other than installing bun in the workflow and running bun test how to install bun in a github actions workflow to use bun test in a github actions workflow add the following step github workflows test yml jobs build name build app runs on ubuntu latest steps name checkout uses actions checkout v4 name install bun uses oven sh setup bun v2 name install dependencies assuming your project has dependencies run bun install you can use npm yarn pnpm instead if you prefer name run tests run bun test junit xml reports gitlab etc to write a junit xml report pass reporter junit together with reporter outfile terminal bun test reporter junit reporter outfile bun xml bun test still writes to stdout stderr as usual and writes the junit xml report to the given path at the end of the run junit xml is a popular format for reporting test results in ci cd pipelines timeouts use the timeout flag to specify a per test timeout in milliseconds if a test times out it is marked as failed the default value is 5000 terminal default value is 5000 bun test timeout 20 concurrent test execution by default bun runs all tests sequentially within each test file concurrent execution runs async tests in parallel which speeds up test suites with independent tests concurrent flag use the concurrent flag to run all tests concurrently within their respective files terminal bun test concurrent when this flag is enabled all tests run in parallel unless marked with test serial max concurrency flag control the maximum number of tests running simultaneously with the max concurrency flag terminal limit to 4 concurrent tests bun test concurrent max concurrency 4 default 20 bun test concurrent this helps prevent resource exhaustion when running many concurrent tests the default value is 20 test concurrent mark individual tests to run concurrently even when the concurrent flag is not used math test ts import test expect from bun test these tests run in parallel with each other test concurrent concurrent test 1 async await fetch api endpoint1 expect true tobe true test concurrent concurrent test 2 async await fetch api endpoint2 expect true tobe true this test runs sequentially test sequential test expect 1 1 tobe 2 test serial force tests to run sequentially even when the concurrent flag is enabled math test ts import test expect from bun test let sharedstate 0 these tests must run in order test serial first serial test sharedstate 1 expect sharedstate tobe 1 test serial second serial test depends on the previous test expect sharedstate tobe 1 sharedstate 2 this test can run concurrently if concurrent is enabled test independent test expect true tobe true chaining test qualifiers test failing each 1 2 3 chained qualifiers d input expect input tobe 0 this test is expected to fail for each input retry failed tests use the retry flag to automatically retry failed tests up to a given number of times if a test fails and then passes on a subsequent attempt it is reported as passing terminal bun test retry 3 per test retry n overrides the global retry value uses the global retry value test uses global retry overrides retry with its own value test custom retry retry 1 you can also set this in bunfig toml bunfig toml test retry 3 rerun tests use the rerun each flag to run each test multiple times this surfaces flaky or non deterministic test failures terminal bun test rerun each 100 randomize test execution order use the randomize flag to run tests in a random order this helps detect tests that depend on shared state or execution order terminal bun test randomize with randomize the seed used for randomization is displayed in the test summary terminal bun test randomize test output seed 12345 2 pass 8 fail ran 10 tests across 2 files 50 00ms reproducible random order with seed use the seed flag to specify the randomization seed and reproduce the same test order when debugging order dependent failures terminal reproduce a previous randomized run bun test seed 123456 the seed flag implies randomize so you don t need to specify both the same seed always produces the same test execution order bail out with bail use the bail flag to abort the test run after a given number of test failures by default bun runs all tests and reports all failures but in ci it can be preferable to stop early and reduce cpu usage terminal bail after 1 failure bun test bail bail after 10 failure bun test bail 10 watch mode like bun run bun test accepts the watch flag to watch for changes and re run tests terminal bun test watch lifecycle hooks bun supports the following lifecycle hooks hook description beforeall runs once before all tests beforeeach runs before each test aftereach runs after each test afterall runs once after all tests define hooks inside test files or in a separate file preloaded with the preload flag terminal bun test preload setup ts see lifecycle mocks create mock functions with the mock function math test ts import test expect mock from bun test const random mock math random test random const val random expect val tobegreaterthan 0 expect random tohavebeencalled expect random tohavebeencalledtimes 1 alternatively use jest fn it behaves identically math test ts import test expect mock from bun test import test expect jest from bun test const random mock math random const random jest fn math random see mocks snapshot testing bun test supports snapshot testing math test ts example usage of tomatchsnapshot import test expect from bun test test snapshot expect a 1 tomatchsnapshot to update snapshots use the update snapshots flag terminal bun test update snapshots see snapshots ui dom testing bun is compatible with popular ui testing libraries happydom dom testing library react testing library see dom testing performance bun s test runner is fast ai agent integration when you use bun s test runner with an ai coding assistant you can enable quieter output that keeps failure details but drops the rest of the noise environment variables set any of the following environment variables to enable ai friendly output claudecode 1 for claude code repl_id 1 for replit agent 1 generic ai agent flag behavior when an ai agent environment is detected only test failures are displayed in detail passing skipped and todo test indicators are hidden summary statistics remain intact terminal example enable quiet output for claude code claudecode 1 bun test still shows failures and summary but hides verbose passing test output cli usage bun test pattern s execution control timeout number default 5000 set the per test timeout in milliseconds default 5000 rerun each number re run each test file number times to help catch certain bugs retry number retry failed tests up to number times overridden by per test concurrent boolean treat all tests as test concurrent tests randomize boolean run tests in random order seed number set the random seed for test randomization bail number default 1 exit the test suite after number failures if you do not specify a number it defaults to 1 max concurrency number default 20 maximum number of concurrent tests to execute at once default 20 test filtering todo boolean include tests that are marked with test todo test name pattern string run only tests with a name that matches the given regex alias t reporting reporter string test output reporter format available junit requires reporter outfile dots default console output reporter outfile string output file path for the reporter format required with reporter dots boolean enable dots reporter shorthand for reporter dots coverage coverage boolean generate a coverage profile coverage reporter string default text report coverage in text and or lcov defaults to text coverage dir string default coverage directory for coverage files defaults to coverage snapshots update snapshots boolean update snapshot files alias u examples run all test files terminal bun test run all test files with foo or bar in the file name terminal bun test foo bar run all test files only including tests whose name includes baz terminal bun test test name pattern baz was this page helpful yes no suggest edits raise issue writing tests next i x github discord youtube powered by this documentation is built and hosted on mintlify a developer documentation platform
|