effect
effect copied to clipboard
Expose Vitest TestContext info as a layer resolved by `it.effect`
What is the problem this feature would solve?
The Vitest TestContext is useful for accessing test metadata. In particular, the task within the TestContext can be useful for building the layers used by the test.
Consider for instance declaring a layer that auto creates a unique database per test based on the task's id and cleans it up at the end.
What is the feature you are proposing to solve the problem?
Declare something like:
import * as V from "vitest";
export class VitestTestContext extends Context.Tag("@effect/vitest/VitestTestContext")<VitestTestContext, V.TestContext>(){}
and then automatically provide an instance for it.effect
What alternatives have you considered?
We can always just manually provide the Vitest TestContext but it's cumbersome.
it.effect("my test", (ctx) => Effect.gen(function*() {
...
}).pipe(Effect.provide(mkTestLayer(ctx)))
;
There are ways to simplify this, but nicer if it were built into @effect/vitest directly.