| 26 | const defaultApi = Object.assign(V.it, { scopedFixtures: V.it.scoped }) |
| 27 | |
| 28 | const 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 */ |
| 59 | const runTest = (ctx?: Vitest.TestContext) => <E, A>(effect: Effect.Effect<A, E>) => runPromise(ctx)(effect) |