test(core): cover Effect Schema event definitions

Exercise the new SyncEvent and BusEvent Schema overloads end to end and use Schema.isSchema for the conversion check so the mixed-schema path stays explicit and covered.
This commit is contained in:
Kit Langton
2026-04-23 08:43:35 -04:00
parent 3085279724
commit 96039bdb83
4 changed files with 67 additions and 6 deletions
+19
View File
@@ -1,4 +1,5 @@
import { afterEach, describe, expect, test } from "bun:test"
import { Schema } from "effect"
import z from "zod"
import { Bus } from "../../src/bus"
import { BusEvent } from "../../src/bus/bus-event"
@@ -10,6 +11,8 @@ const TestEvent = {
Pong: BusEvent.define("test.pong", z.object({ message: z.string() })),
}
const EffectTestEvent = BusEvent.define("test.effect-schema.ping", Schema.Struct({ value: Schema.Number }))
function withInstance(directory: string, fn: () => Promise<void>) {
return Instance.provide({ directory, fn })
}
@@ -76,6 +79,22 @@ describe("Bus", () => {
await Bus.publish(TestEvent.Ping, { value: 1 })
})
})
test("accepts Effect Schema event definitions", async () => {
await using tmp = await tmpdir()
const received: number[] = []
await withInstance(tmp.path, async () => {
Bus.subscribe(EffectTestEvent, (evt) => {
received.push(evt.properties.value)
})
await Bun.sleep(10)
await Bus.publish(EffectTestEvent, { value: 42 })
await Bun.sleep(10)
})
expect(received).toEqual([42])
})
})
describe("unsubscribe", () => {