Effect testing utilities for Bun.
bun add -d effect-bun-testimport { Effect, TestClock } from "effect";
import { describe, it, expect, yieldFibers } from "effect-bun-test";
describe("my feature", () => {
// Run with TestContext (includes TestClock)
it.effect("handles time-based logic", () =>
Effect.gen(function* () {
yield* TestClock.adjust("1 second");
expect(true).toBe(true);
}),
);
// Run scoped effect with TestContext
it.scoped("cleans up resources", () =>
Effect.gen(function* () {
const resource = yield* Effect.acquireRelease(Effect.succeed("handle"), () =>
Effect.log("released"),
);
// resource auto-released after test
}),
);
// Run with real clock (no TestContext)
it.live("uses actual delays", () =>
Effect.gen(function* () {
yield* Effect.sleep("10 millis");
}),
);
// Yield to forked fibers
it.effect("waits for async work", () =>
Effect.gen(function* () {
let done = false;
yield* Effect.fork(
Effect.sync(() => {
done = true;
}),
);
yield* yieldFibers;
expect(done).toBe(true);
}),
);
});| Method | TestContext | Scope | Use Case |
|---|---|---|---|
it.effect |
✓ | Time-controlled tests | |
it.scoped |
✓ | ✓ | Tests with resource cleanup |
it.live |
Real clock tests | ||
it.scopedLive |
✓ | Real clock + resource cleanup |
yieldFibers- Yield to allow forked fibers to process (use afterforkorsend)describe,test,expect- Re-exported frombun:test
MIT