MCPcopy Create free account
hub / github.com/Effect-TS/effect / runPromise

Function runPromise

packages/vitest/src/internal/internal.ts:28–56  ·  view source on GitHub ↗
(ctx?: Vitest.TestContext)

Source from the content-addressed store, hash-verified

26const defaultApi = Object.assign(V.it, { scopedFixtures: V.it.scoped })
27
28const runPromise = (ctx?: Vitest.TestContext) => <E, A>(effect: Effect.Effect<A, E>) =>
29 Effect.gen(function*() {
30 const exitFiber = yield* Effect.fork(Effect.exit(effect))
31
32 ctx?.onTestFinished(() =>
33 Fiber.interrupt(exitFiber).pipe(
34 Effect.asVoid,
35 Effect.runPromise
36 )
37 )
38
39 const exit = yield* Fiber.join(exitFiber)
40 if (Exit.isSuccess(exit)) {
41 return () => exit.value
42 } else {
43 if (Cause.isInterruptedOnly(exit.cause)) {
44 return () => {
45 throw new Error("All fibers interrupted without errors.")
46 }
47 }
48 const errors = Cause.prettyErrors(exit.cause)
49 for (let i = 1; i < errors.length; i++) {
50 yield* Effect.logError(errors[i])
51 }
52 return () => {
53 throw errors[0]
54 }
55 }
56 }).pipe((effect) => Effect.runPromise(effect, { signal: ctx?.signal })).then((f) => f())
57
58/** @internal */
59const runTest = (ctx?: Vitest.TestContext) => <E, A>(effect: Effect.Effect<A, E>) => runPromise(ctx)(effect)

Callers 2

runTestFunction · 0.70
layerFunction · 0.70

Calls 5

fFunction · 0.70
pipeMethod · 0.65
forkMethod · 0.65
joinMethod · 0.65
interruptMethod · 0.45

Tested by

no test coverage detected