2.6 KiB
2.6 KiB
id, name, status, depends_on, scope, risk, impact, level
| id | name | status | depends_on | scope | risk | impact | level |
|---|---|---|---|---|---|---|---|
| core-pubsub-tests | Write tests for createPubSub, EventEnvelope, and in-process event target | completed | moderate | low | component | implementation |
Description
The core createPubSub factory, EventEnvelope type, and the in-process (default EventTarget) path have no tests. These are the foundation of the entire package — every adapter builds on createPubSub. Write comprehensive tests that verify the core contract.
The architecture specifies these behaviors:
createPubSub()with no config usesnew EventTarget()(in-process)createPubSub({ eventTarget })uses a custom event targetpublish(type, id, payload)dispatches aCustomEventwith type"type:id"anddetailasEventEnvelopesubscribe(type, id)returns aRepeater<EventEnvelope>(async iterable)publishthrows on event types starting with__(reserved for adapter control)- Topic scoping uses the
type:idconvention subscribecleanup: breaking out of thefor awaitloop removes the listener
Acceptance Criteria
test/create_pubsub.test.tsexists and passes- Test:
publishdispatches event with correcttype:idtopic - Test:
publishthrows on__-prefixed event types - Test:
subscribereturns async iterable that yieldsEventEnvelopeobjects - Test:
subscribeenvelope has correcttype,id,payloadfields - Test: subscriber receives events only for the subscribed topic (type:id matching)
- Test: multiple subscribers on the same topic all receive events
- Test: subscriber cleanup — breaking out of
for awaitloop removes the listener - Test:
createPubSubwith customeventTargetdispatches to that target - Test:
createPubSubwithouteventTargetusesnew EventTarget()(in-process)
References
- docs/architecture/api-surface.md
- src/create_pubsub.ts
- src/types.ts
Notes
Used subscribe-based testing approach since createPubSub doesn't expose the internal target. Custom eventTarget tests use vi.spyOn on the provided target's dispatchEvent method.
Summary
Implemented comprehensive tests for createPubSub, EventEnvelope, and in-process event target.
- Created: test/create_pubsub.test.ts
- Tests: 11, all passing
- Coverage: publish dispatches correct type:id topic, publish throws on __-prefixed types, subscribe yields EventEnvelope objects, envelope has correct type/id/payload, topic scoping (type:id matching), multiple subscribers receive events, subscriber cleanup on break, custom eventTarget dispatches to provided target, default in-process EventTarget works