Something went wrong. Try again.
opencode v2 mirror
Something went wrong. Try again.
1.1 kB · 30 lines
TypeScript
12345678910111213141516171819202122232425262728293031import { test } from "bun:test"import { Cause, Effect, Exit, Layer } from "effect"import type { Scope } from "effect/Scope"import { TestClock, TestConsole } from "effect/testing"
type Body<A, E, R> = Effect.Effect<A, E, R> | (() => Effect.Effect<A, E, R>)
const layer = Layer.mergeAll(TestConsole.layer, TestClock.layer())
const make = <R>(testLayer: Layer.Layer<R>) => <A, E>(name: string, body: Body<A, E, Scope>, options?: Parameters<typeof test>[2]) => test( name, () => Effect.gen(function* () { const exit = yield* Effect.suspend(() => (typeof body === "function" ? body() : body)).pipe( Effect.scoped, Effect.provide(testLayer), Effect.exit, ) if (Exit.isFailure(exit)) { yield* Effect.forEach(Cause.prettyErrors(exit.cause), Effect.logError, { discard: true }) } return yield* exit }).pipe(Effect.runPromise), options, )
export const it = { effect: make(layer), live: make(TestConsole.layer) }