Skip to content

Support Effects in vitest setup hooks (Reopened from V3) #8246

Description

@chmnchiang

What is the problem this feature would solve?

This is the same as #6096, but for V4. Credit to @dmeehan1968 and @coyaSONG

Paste the original FR here:

Description

@effect/vitest currently re-exports Vitest's beforeAll and beforeEach hooks unchanged. Vitest does not recognize a returned Effect as asynchronous work, so the Effect remains lazy and the hook body is skipped.

This change explicitly wraps both hooks. When a callback returns an Effect, it is executed and awaited through the package's existing Effect runner; synchronous and Promise-returning callbacks are passed through unchanged. Regression tests cover both suite-level and per-test Effect hooks, including the repository's concurrent test configuration.

I think effect/vitest should just wrap all the hooks. Including

  • {before,after,around}{Each,All}

What is the feature you are proposing to solve the problem?

A solution, similar to #6450, but the effect should also have access to the outer layer injected by it.layer.

What alternatives have you considered?

Wrap the effect in Effect.runPromise myself in vanilla vitest beforeEach. However, they don't have access to the layer.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions