event-types.test.ts 1.0 KB

1234567891011121314151617181920212223242526
  1. import { expect, test } from "bun:test"
  2. import type { Context as EffectContext } from "../src/effect/plugin.js"
  3. import type { Context as PromiseContext } from "../src/promise/plugin.js"
  4. function effectSubscriptions(ctx: EffectContext) {
  5. ctx.event.subscribe()
  6. ctx.event.subscribe("config.updated")
  7. // @ts-expect-error server.connected is a network-only marker
  8. ctx.event.subscribe("server.connected")
  9. // @ts-expect-error plugin subscriptions select at most one event type
  10. ctx.event.subscribe(["config.updated"])
  11. }
  12. function promiseSubscriptions(ctx: PromiseContext) {
  13. ctx.event.subscribe()
  14. ctx.event.subscribe("config.updated")
  15. // @ts-expect-error server.connected is a network-only marker
  16. ctx.event.subscribe("server.connected")
  17. // @ts-expect-error plugin subscriptions select at most one event type
  18. ctx.event.subscribe(["config.updated"])
  19. }
  20. test("event subscription types support wildcard and one public event", () => {
  21. expect(effectSubscriptions).toBeFunction()
  22. expect(promiseSubscriptions).toBeFunction()
  23. })