Skip to main content

workers/host/mockWorker

@arolariu/website


@arolariu/website / workers/host/mockWorker

workers/host/mockWorker

Fileoverview

Test utility: a controllable Worker-shaped object backed by the worker-side expose runtime, with no real worker thread involved.

Remarks

Used exclusively by foundation unit tests. Lets us drive the host through every state transition deterministically, and feeds Comlink real MessagePorts so error normalization round-trips end-to-end.

Not exported from any barrel; not bundled in production.

KNOWN FIDELITY GAPS vs. a real Worker — these are exercised in the Playwright suite at src/app/playground/workers/worker-playground.spec.ts, not here:

  • Realm isolation: closures share the host realm. Passing a non-cloneable value (e.g., a function) does NOT throw the way structured clone would in a real Worker.
  • messageerror event: dispatchable via simulateMessageError(). Note that real workers may fire messageerror parallel to in-flight calls (HTML §10.2.4); the mock fires it synchronously when called.
  • Boot latency: synchronous. Real workers have ~1–10ms startup.
  • Parallel terminate(): synchronous. Per WHATWG HTML §10.2.4, real terminate() queues a task; an error event can fire after terminate() returns.
  • Off-thread execution: runs on the main thread. Race conditions that depend on actual parallelism may pass MockWorker tests and regress in production.

Type Aliases

Functions

// was this page useful?