MockBridge interface

Module @runic-artifex/views/mock in @runic-artifex/views 0.23.0

interface MockBridge extends RunicBridgeClient

An in-memory __runicBridge: a Views protocol 4 producer for generated clients without .NET.

Properties

calls

readonly calls: readonly MockCall[];

Every request in order, including hello and rejected ones.

clientErrors

readonly clientErrors: readonly MockClientError[];

client-errors/1: the error reports the page sent with installErrorReporting, in order.

now

readonly now: number;

The virtual time in milliseconds, which only advance() moves.

pending

readonly pending: number;

Queued requests, replies, pushes and timers that are due now or later.

windowLocale

readonly windowLocale: string | null;

The window's locale that MockBridge set, or null.

appearance

readonly appearance: HostAppearance | null;

The window's appearance that MockBridge set, every member present, or null.

clientLanguages

readonly clientLanguages: readonly string[];

client-languages/1: the languages the page's last hello reported (its browser's navigator.languages), as a .NET producer reports them on RunicConnection.Languages: in BCP 47 case, each once. [] before a hello that uses the feature.

uploads

readonly uploads: readonly MockUpload[];

blobs/1: every upload the mock stored, in order.

Methods

view

view(route: string, definition: MockViewDefinition): MockView;

Serves a View on route: open, close, snapshot, set, write, command, can and operations.

intercept

intercept(handler: MockInterceptor): () => void;

Answers requests before the mock does, until the returned function is called.

push

push(message: Readonly<Record<string, unknown>>): void;

Pushes a message to the connected page, such as a menu-bar push.

failNext

failNext(match: MockRequestMatch, failure: MockFailure, times?: number): void;

Answers the next times requests that match with failure.

disconnect

disconnect(): void;

Rejects further requests until reconnect() and reports the loss to onConnectionChange listeners. Like a producer when a connection closes, it closes the connection's presentations and watches, and a later hello with its session answers released.

reconnect

reconnect(): void;

Reports a new connection to onConnectionChange listeners, as a host transport does after a reconnect.

closeWindow

closeWindow(timeout?: number, options?: {
    readonly draining?: boolean;
}): Promise<boolean>;

Closes the window as the application does (presented/1): pushes closing to the connection when it uses the feature and resolves with whether the page answered closing-reply within timeout milliseconds (default 5000; virtual time with manual scheduling). false also when the connection closes first; true at once when the connection does not use the feature, as RunicWindowCloseResult.PagesAcknowledged. A second call on the same connection returns the first result. The connection stays open: call disconnect() to end it as a host does. { draining: true } closes it with a close drain (experimental, 0.19): the push says draining: true, and the window keeps pushing its state until disconnect().

pushNavigationPath

pushNavigationPath(path: string | null, operation: "push" | "back" | "replace"): void;

Pushes the window's route path to the connection when it uses navigation-path/1, as the application's navigation of the path region does, and makes it the path of later hello replies.

flushFields

flushFields(timeout?: number): Promise<boolean>;

Asks the page to write its field drafts before a departure, as the application does before it asks a departure guard (field-flush/1): pushes flush and resolves with whether the page answered flush-reply within timeout milliseconds (default 1000; virtual time with manual scheduling). true at once when the connection does not use the feature, which the application then skips.

setWindowLocale

setWindowLocale(locale: string | null): void;

Sets the window's locale as the application does with IRunicWindowLocale (translation-text/1): pushes locale to the connection when it uses the feature, and again after the hello of each later connection. null stops pushing it; the page keeps the language it shows.

setAppearance

setAppearance(appearance: Partial<HostAppearance> | null, options?: {
    readonly override?: readonly ("colorScheme" | "contrast" | "reducedMotion")[];
}): void;

Sets the window's appearance as a desktop host does from the desktop's settings (appearance/1, WindowContentSession.Appearance in .NET): pushes appearance with every member to the connection when it uses the feature, and again after the hello of each later connection, which gets every member null before the first call. A member left out is null; null makes every member null. Setting an equal appearance pushes nothing. options.override lists the members the host decided for the window rather than read from the desktop, as for a guest's page in a hosted region: the push carries them as override, without members whose value is null, and the page's appearance prefers them over its engine's media queries.

sleep

sleep(milliseconds: number): Promise<void>;

Resolves after milliseconds of virtual time, for handlers that model latency.

flush

flush(): Promise<void>;

Delivers every queued request, reply and push that is due, until the client is idle, and the client's pending subscriber notifications.

flushUntil

flushUntil<T>(promise: Promise<T>): Promise<T>;

Flushes until promise settles, then returns its result. Fails when it cannot settle without time passing.

advance

advance(milliseconds: number): Promise<void>;

Moves the virtual clock, delivering timed work in order.

uploadContent

uploadContent(upload: BlobRef | string): Blob | undefined;

blobs/1: the content of an upload, by its reference or id; undefined for one the mock did not store.

failNextUpload

failNextUpload(failure: MockUploadFailure): void;

blobs/1: answers the next upload with an HTTP failure instead of storing it.

upload

upload(request: HostUploadRequest): Promise<{
    readonly status: number;
    readonly body: string;
}>;

blobs/1: receives an upload as a host does (the host bridge's upload, which upload() calls). It reports progress at half and at the end of the content, one latency apart, and stops when the request's signal aborts.