GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: use Effect test helper for run-service (#25048) · Verdagon/opencode@f384675

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/opencode/test/effect
    • run-service.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/opencode/test/effect/run-service.test.ts‎

Copy file name to clipboard
+39-36Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,49 @@
1-
import { expect, test } from "bun:test"
1+
import { expect } from "bun:test"
22
import { Effect, Layer, Context } from "effect"
33
import { makeRuntime } from "../../src/effect/run-service"
4+
import { it } from "../lib/effect"
45

56
class Shared extends Context.Service<Shared, { readonly id: number }>()("@test/Shared") {}
67

7-
test("makeRuntime shares dependent layers through the shared memo map", async () => {
8-
let n = 0
8+
it.live("makeRuntime shares dependent layers through the shared memo map", () =>
9+
Effect.gen(function* () {
10+
let n = 0
911

10-
const shared = Layer.effect(
11-
Shared,
12-
Effect.sync(() => {
13-
n += 1
14-
return Shared.of({ id: n })
15-
}),
16-
)
12+
const shared = Layer.effect(
13+
Shared,
14+
Effect.sync(() => {
15+
n += 1
16+
return Shared.of({ id: n })
17+
}),
18+
)
1719

18-
class One extends Context.Service<One, { readonly get: () => Effect.Effect<number> }>()("@test/One") {}
19-
const one = Layer.effect(
20-
One,
21-
Effect.gen(function* () {
22-
const svc = yield* Shared
23-
return One.of({
24-
get: Effect.fn("One.get")(() => Effect.succeed(svc.id)),
25-
})
26-
}),
27-
).pipe(Layer.provide(shared))
20+
class One extends Context.Service<One, { readonly get: () => Effect.Effect<number> }>()("@test/One") {}
21+
const one = Layer.effect(
22+
One,
23+
Effect.gen(function* () {
24+
const svc = yield* Shared
25+
return One.of({
26+
get: Effect.fn("One.get")(() => Effect.succeed(svc.id)),
27+
})
28+
}),
29+
).pipe(Layer.provide(shared))
2830

29-
class Two extends Context.Service<Two, { readonly get: () => Effect.Effect<number> }>()("@test/Two") {}
30-
const two = Layer.effect(
31-
Two,
32-
Effect.gen(function* () {
33-
const svc = yield* Shared
34-
return Two.of({
35-
get: Effect.fn("Two.get")(() => Effect.succeed(svc.id)),
36-
})
37-
}),
38-
).pipe(Layer.provide(shared))
31+
class Two extends Context.Service<Two, { readonly get: () => Effect.Effect<number> }>()("@test/Two") {}
32+
const two = Layer.effect(
33+
Two,
34+
Effect.gen(function* () {
35+
const svc = yield* Shared
36+
return Two.of({
37+
get: Effect.fn("Two.get")(() => Effect.succeed(svc.id)),
38+
})
39+
}),
40+
).pipe(Layer.provide(shared))
3941

40-
const { runPromise: runOne } = makeRuntime(One, one)
41-
const { runPromise: runTwo } = makeRuntime(Two, two)
42+
const { runPromise: runOne } = makeRuntime(One, one)
43+
const { runPromise: runTwo } = makeRuntime(Two, two)
4244

43-
expect(await runOne((svc) => svc.get())).toBe(1)
44-
expect(await runTwo((svc) => svc.get())).toBe(1)
45-
expect(n).toBe(1)
46-
})
45+
expect(yield* Effect.promise(() => runOne((svc) => svc.get()))).toBe(1)
46+
expect(yield* Effect.promise(() => runTwo((svc) => svc.get()))).toBe(1)
47+
expect(n).toBe(1)
48+
}),
49+
)

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.