zidane-ui/ extensions/ testing/ contract
import { … } from 'zidane-ui/extensions/testing/contract'ui/src/extensions/testing/contract.ts
Functions#
describeExtensionsHostContractFunction#
Declares the shared ExtensionsHost suite for one implementation.
function describeExtensionsHostContract(
name: string,
makeHarness: ExtensionsHostHarnessFactory,
capabilities: readonly ExtensionsHostCapability[],
): voidParameters
| Name | Type | Description |
|---|---|---|
| name | string | The implementation's name, shown in the suite title. |
| makeHarness | ExtensionsHostHarnessFactory | Builds a fresh host over a backend that does what it is given, once per test. |
| capabilities | readonly ExtensionsHostCapability[] | The optional members the host offers. Every other optional member must be undefined. |
Constants#
CONTRACT_GOOD_KEYConstant#
The API key the backend's integrations accept.
const CONTRACT_GOOD_KEY = 'good-key'CONTRACT_STOREConstant#
The store the storage tests read and write.
const CONTRACT_STORE: ExtensionStoreRefInterfaces#
ExtensionsHostContractBackendInterface#
What the backend behind the host holds and does.
interface ExtensionsHostContractBackendProperties
| Name | Type | Description |
|---|---|---|
| callbacks | { 'badge.menu'?: (args: { target: BadgeTarget }) => readonly BadgeMenuItem[]; 'badge.run'?: (args: { actionId: string; cwd?: string; sessionId?: string; source: string; target: BadgeTarget }) => BadgeActionEffect; 'panel.action'?: (args: { actionId: string; context?: unknown; cwd: string; panelId: string; payload?: unknown }) => boolean; 'panel.load'?: (args: { context?: unknown; cwd: string; panelId: string }) => PanelContent; 'reference.resolve'?: (args: { key: string; providerId: string }) => ExtensionReferenceView | null; 'setting.action'?: (args: { key: string; pageId: string }) => { message?: string; patch?: Readonly<Record<string, string | number | boolean | readonly string[]>>; tone?: 'error' | 'success' | 'warn' | 'info' } | undefined; 'setting.status'?: (args: { key: string; pageId: string }) => { text: string; tone?: 'error' | 'muted' | 'success' | 'warn' } | undefined } | What each callback answers. A callback that throws answers |
| commands | readonly ExtensionCommandWire[] | The commands. Running an unknown id answers |
| integrations | readonly ExtensionIntegrationWire[] | The integrations. |
| items | readonly ExtensionItem<keyof ExtensionWireMap>[] | The items there at the start. |
| rpc | Readonly<Record<string, Readonly<Record<string, ContractRpcMethod>>>> | RPC methods, by contract then method. |
| settings | ExtensionSettingsWire | The settings. The backend refuses a write to a locked key ( |
| storeValue | unknown | The stored value of |
ExtensionsHostContractControlInterface#
Drives the backend from outside.
interface ExtensionsHostContractControlProperties
| Name | Type | Description |
|---|---|---|
| dialog | (request: DialogRequest, ctx: { extensionId: string; sessionId?: string; signal?: AbortSignal }) => Promise<unknown> | An extension asked for a dialog routed to this client; resolves with the answer. |
| effect | (effect: ExtensionUiEffect) => Promise<ExtensionUiEffectResult> | An extension's |
| ran | () => readonly { args?: string; id: string; sessionId?: string }[] | The commands the backend ran. |
| readStore | () => unknown |
|
| remove | (key: string) => void | An extension withdrew an item. |
| upsert | (entry: ExtensionItem) => void | An extension added or changed an item. |
| writeStore | (value: unknown) => void | Another client wrote |
ExtensionsHostHarnessInterface#
A host built over a backend, the backend's control, and how to tear them down.
interface ExtensionsHostHarnessProperties
| Name | Type | Description |
|---|---|---|
| control | ExtensionsHostContractControl | Drives the backend the host talks to. |
| host | ExtensionsHost | The host under test. |
| dispose? | () => void | Tears the host and its backend down after the test. |
Types#
ContractRpcMethodType#
A scripted RPC method: returns its output, or throws { type, message, data? } to answer that error.
type ContractRpcMethod = (input: unknown) => unknownExtensionsHostCapabilityType#
An optional ExtensionsHost member. settings.set is the settings' write.
type ExtensionsHostCapability =
| 'invoke'
| 'dialogs'
| 'effects'
| 'rpc'
| 'storage'
| 'settings'
| 'settings.set'
| 'integrations'
| 'commands'ExtensionsHostHarnessFactoryType#
Builds a fresh host (and its backend) for one test.
type ExtensionsHostHarnessFactory = (backend: ExtensionsHostContractBackend) => ExtensionsHostHarness | Promise<ExtensionsHostHarness>