Skip to content
Latchkey

Bun "test failed" nonzero exit code (bun test) in CI

At least one test failed, so bun test exits nonzero and the CI step fails. The summary line reports how many passed and failed; the real signal is the first failing assertion above it.

What this error means

A bun test step ends with "N fail" and a nonzero exit, failing the job even though individual passing tests are shown.

Terminal
 5 pass
 1 fail
 6 expect() calls
error: 1 test failed
Ran 6 tests across 2 files.

Common causes

A genuine assertion failure

A test's expectation did not hold on the runner, so bun test records a failure and exits nonzero.

Environment differences between local and CI

Missing env vars, a different timezone, or absent services make a test that passes locally fail in CI.

How to fix it

Read the failing assertion and reproduce

  1. Scroll to the first (fail) block to see expected versus received.
  2. Run only that test locally with bun test <file> -t "<name>".
  3. Fix the code or the test and re-run.
Terminal
bun test src/format.test.ts -t "formats dates"

Provide the CI environment the test needs

Set required env vars and services in the workflow so CI matches the assumptions the test makes.

.github/workflows/ci.yml
- run: bun test
  env:
    TZ: UTC
    DATABASE_URL: ${{ secrets.DATABASE_URL }}

How to prevent it

  • Keep tests deterministic and independent of local-only state.
  • Set required env vars and services in CI.
  • Run bun test locally before pushing.

Frequently asked questions

What causes ""test failed" (bun test)"?
A test's expectation did not hold on the runner, so bun test records a failure and exits nonzero.
How do I fix "test failed" (bun test)?
Read the failing assertion and reproduce

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card