Files
hermes-agent/apps/desktop/src/test/deferred.ts
T
Brooklyn Nicholson 808fde106d test(desktop): share the duplicated fixtures
The same AST sweep over specs found fixtures maintained in parallel
across suites that have no reason to know about each other.

Twenty-one specs each mounted useMessageStream themselves and ten of the
harnesses were byte-identical; twenty now take renderMessageStream, with
overrides for the seams that genuinely vary. The SessionInfo builder was
spelled out field-by-field in seven specs, so a new backend field broke
seven files instead of one. Twenty specs carried their own inert
ResizeObserver and eleven repeated the animation-frame, CSS.escape,
scrollTo and WAAPI stubs the transcript needs to mount at all — split by
scope into src/test/jsdom for what any component might need and the
assistant-ui folder's own kit for the transcript. Plus the window-state
bridge, deferred, the external-store thread runtime, the manual
createRoot harness, and the per-folder caret, env-var, provider and
session fixtures.

Left alone on purpose: the store suites' makePrimary, where the vi.mock
harness around it is the actual duplication and cannot be hoisted out of
a hoisted factory; electron's deferred, where reaching into src/ from
the main process would invert the layering for eight lines; and the two
suites that compose another hook alongside the stream.
2026-08-19 10:51:12 -05:00

17 lines
527 B
TypeScript

/** A promise plus the handle that settles it.
*
* For tests that need a call to stay in flight — asserting the pending UI,
* proving a second call is coalesced or ignored, ordering two resolutions —
* and then release it on their own schedule. */
export function deferred<T = void>() {
let resolve!: (value: PromiseLike<T> | T) => void
let reject!: (reason?: unknown) => void
const promise = new Promise<T>((done, fail) => {
resolve = done
reject = fail
})
return { promise, reject, resolve }
}