test: use Effect test helper for run-service (#25048)
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
import { expect, test } from "bun:test"
|
import { expect } from "bun:test"
|
||||||
import { Effect, Layer, Context } from "effect"
|
import { Effect, Layer, Context } from "effect"
|
||||||
import { makeRuntime } from "../../src/effect/run-service"
|
import { makeRuntime } from "../../src/effect/run-service"
|
||||||
|
import { it } from "../lib/effect"
|
||||||
|
|
||||||
class Shared extends Context.Service<Shared, { readonly id: number }>()("@test/Shared") {}
|
class Shared extends Context.Service<Shared, { readonly id: number }>()("@test/Shared") {}
|
||||||
|
|
||||||
test("makeRuntime shares dependent layers through the shared memo map", async () => {
|
it.live("makeRuntime shares dependent layers through the shared memo map", () =>
|
||||||
|
Effect.gen(function* () {
|
||||||
let n = 0
|
let n = 0
|
||||||
|
|
||||||
const shared = Layer.effect(
|
const shared = Layer.effect(
|
||||||
@@ -40,7 +42,8 @@ test("makeRuntime shares dependent layers through the shared memo map", async ()
|
|||||||
const { runPromise: runOne } = makeRuntime(One, one)
|
const { runPromise: runOne } = makeRuntime(One, one)
|
||||||
const { runPromise: runTwo } = makeRuntime(Two, two)
|
const { runPromise: runTwo } = makeRuntime(Two, two)
|
||||||
|
|
||||||
expect(await runOne((svc) => svc.get())).toBe(1)
|
expect(yield* Effect.promise(() => runOne((svc) => svc.get()))).toBe(1)
|
||||||
expect(await runTwo((svc) => svc.get())).toBe(1)
|
expect(yield* Effect.promise(() => runTwo((svc) => svc.get()))).toBe(1)
|
||||||
expect(n).toBe(1)
|
expect(n).toBe(1)
|
||||||
})
|
}),
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user