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
- Scroll to the first
(fail)block to see expected versus received. - Run only that test locally with
bun test <file> -t "<name>". - 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.
Related guides
Bun "expect(received).toBe(expected)" assertion failure in CIFix bun:test assertion failures in CI - an expect() matcher did not hold. Read the expected versus received v…
Bun test "ENOENT" reading a fixture / file in CIFix "ENOENT: no such file or directory" during bun test in CI - a test reads a fixture by a path that does no…
Bun "TypeError: X is not a function" (Node API gap) in CIFix Bun "TypeError: X is not a function" in CI - a Node.js API a dependency calls is not implemented (or diff…