Files
pubsub/tasks/013-worker-adapter-tests.md

1.6 KiB

id, name, status, depends_on, scope, risk, impact, level
id name status depends_on scope risk impact level
worker-adapter-tests Write tests for Worker event target adapter completed
worker-adapter-implementation
moderate medium component implementation

Description

Write tests for the Worker event target adapter(s). Testing Workers is non-trivial because it requires creating actual Worker instances or mocking the postMessage/onmessage API.

Test scenarios from the architecture doc:

  1. Main → Worker send — dispatchEvent from main posts message to worker
  2. Worker → Main send — dispatchEvent from worker posts message to main
  3. Bidirectional — both sides can subscribe and publish
  4. Topic scoping — type:id topics correctly formed
  5. Envelope round-trip — full envelope survives serialization
  6. Worker termination — cleanup when worker exits

Acceptance Criteria

  • test/event-target-worker.test.ts exists and passes
  • Mock strategy for Worker environment established (actual workers, vitest worker threads, or mocked postMessage)
  • Test: host dispatchEvent posts message to worker via postMessage
  • Test: worker thread dispatchEvent posts message to parent
  • Test: bidirectional communication works
  • Test: type:id topic scoping works correctly
  • Test: EventEnvelope round-trips through serialization
  • Test: addEventListener and removeEventListener work on both sides

References

  • docs/architecture/event-targets/worker.md (Test Plan section)
  • src/event-target-worker.ts

Notes

To be filled by implementation agent

Summary

To be filled on completion