import { createOwner } from './owner.ts'; /** Returned values are ignored; returned promises are awaited. */ export type Cleanup = () => unknown; export interface Cleanable { cleanup(): unknown; } export interface Destroyable { destroy(): unknown; } /** The public Radio operations needed to own one reply without importing Radio. */ export interface ReplyChannel { reply(name: string, value: unknown, context?: unknown): unknown; stopReplying(name: string, value: unknown, context?: unknown): unknown; } export interface ReplyRadio { channel(name: string): Channel; } type ReplyMap = Record & ThisType< Context extends null | undefined | false | 0 | 0n | '' ? Channel : // A widened primitive type can also contain a falsy value (including NaN). Context | (0 extends Context ? Channel : '' extends Context ? Channel : 0n extends Context ? Channel : never) >; // Preserve primitive literals for falsy-context inference without freezing objects. type ReplyContext = object | string | number | bigint | boolean | symbol | null | undefined; export interface TestScope extends Cleanable { defer(cleanup: Cleanup): void; own(resource: Resource): Resource; reply(radio: ReplyRadio, channelName: string, name: string, value: unknown, context?: unknown): Channel; reply(radio: ReplyRadio, channelName: string, replies: ReplyMap, context?: Context): Channel; reply(channel: Channel, name: string, value: unknown, context?: unknown): Channel; reply(channel: Channel, replies: ReplyMap, context?: Context): Channel; cleanup(): Promise; } // Own explicitly registered resources; this entry imports neither Marionette nor a runner. export function createTestScope(): TestScope { return createOwner(); }