|
| 1 | +# @effect/bun-test |
| 2 | + |
| 3 | +A set of helpers for testing [Effect](https://effect.website) programs with |
| 4 | +Bun's native [`bun:test`](https://bun.sh/docs/cli/test) runner. |
| 5 | + |
| 6 | +The API mirrors [`@effect/vitest`](https://www.npmjs.com/package/@effect/vitest) |
| 7 | +(`it.effect`, `it.scoped`, `it.live`, `it.scopedLive`, `it.layer`, `it.prop`, |
| 8 | +`flakyTest`, …) but runs under Bun's built-in test runner — useful when you |
| 9 | +already use Bun as your runtime and want to avoid pulling in Vitest. |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +```sh |
| 14 | +bun add -d @effect/bun-test |
| 15 | +``` |
| 16 | + |
| 17 | +## Usage |
| 18 | + |
| 19 | +```ts |
| 20 | +import { describe, expect, it, layer } from "@effect/bun-test" |
| 21 | +import { Context, Effect, Layer } from "effect" |
| 22 | + |
| 23 | +class Foo extends Context.Tag("Foo")<Foo, "foo">() { |
| 24 | + static Live = Layer.succeed(Foo, "foo") |
| 25 | +} |
| 26 | + |
| 27 | +it.effect("plain effect test", () => |
| 28 | + Effect.sync(() => expect(1).toEqual(1)) |
| 29 | +) |
| 30 | + |
| 31 | +describe("with a shared layer", () => { |
| 32 | + layer(Foo.Live)((it) => { |
| 33 | + it.effect("has Foo in context", () => |
| 34 | + Effect.gen(function* () { |
| 35 | + const foo = yield* Foo |
| 36 | + expect(foo).toEqual("foo") |
| 37 | + }) |
| 38 | + ) |
| 39 | + }) |
| 40 | +}) |
| 41 | +``` |
| 42 | + |
| 43 | +Run with: |
| 44 | + |
| 45 | +```sh |
| 46 | +bun test |
| 47 | +``` |
| 48 | + |
| 49 | +## What's supported |
| 50 | + |
| 51 | +| Helper | Status | |
| 52 | +| --- | --- | |
| 53 | +| `it.effect` / `it.scoped` / `it.live` / `it.scopedLive` | ✅ | |
| 54 | +| `.skip`, `.skipIf`, `.runIf`, `.only`, `.each`, `.fails` | ✅ | |
| 55 | +| `.prop` (fast-check integration) | ✅ | |
| 56 | +| `layer(...)` / nested `it.layer(...)` | ✅ | |
| 57 | +| `flakyTest` | ✅ | |
| 58 | +| `addEqualityTesters` (Effect `Equal.equals` integration) | ⚠️ no-op — see below | |
| 59 | + |
| 60 | +### Differences from `@effect/vitest` |
| 61 | + |
| 62 | +Bun's test runner does not expose all of Vitest's APIs. The notable gaps: |
| 63 | + |
| 64 | +- **`addEqualityTesters`** is a no-op — `bun:test`'s `expect` does not yet |
| 65 | + expose `addEqualityTesters`. Use Effect's `Equal.equals` directly (or the |
| 66 | + helpers in `@effect/bun-test/utils`) when comparing values that implement the |
| 67 | + `Equal` trait. |
| 68 | +- **`TestContext`** — Vitest passes a `TestContext` to each test fn (with |
| 69 | + `signal`, `onTestFailed`, `onTestFinished`, etc.). `bun:test` doesn't, so the |
| 70 | + context passed to your Effect tests is a minimal stub. `signal` is a fresh |
| 71 | + `AbortController().signal`; `onTestFailed` / `onTestFinished` register |
| 72 | + best-effort callbacks invoked after the Effect completes. |
| 73 | +- **`scopedFixtures`** (Vitest's `it.scoped(fixtures)`) is not provided — Bun |
| 74 | + has no fixture system. |
| 75 | + |
| 76 | +## License |
| 77 | + |
| 78 | +MIT |
0 commit comments