Skip to content

zidane-ui/terminal/testing/contract

import { … } from 'zidane-ui/terminal/testing/contract'ui/src/terminal/testing/contract.ts

Functions#

describeTerminalHostContractFunction#

Declares the shared TerminalHost suite for one implementation.

TypeScript
function describeTerminalHostContract(
  name: string,
  makeHarness: TerminalHostHarnessFactory,
  capabilities: readonly TerminalHostCapability[],
): void
Parameters
NameTypeDescription
namestring

The implementation's name, shown in the suite title.

makeHarnessTerminalHostHarnessFactory

Builds a fresh host over a backend that holds what it is given, once per test.

capabilitiesreadonly TerminalHostCapability[]

The optional members the host offers. Every other optional member must be undefined.

ui/src/terminal/testing/contract.ts:121

Interfaces#

TerminalHostContractBackendInterface#

What the backend behind the host holds.

TypeScript
interface TerminalHostContractBackend
TerminalHostContractBackend properties
NameTypeDescription
draftsReadonly<Record<string, readonly TerminalInfo[]>>

The terminals per draft id (no session yet).

historyReadonly<Record<string, string>>

What each terminal printed so far, by id.

sessionsReadonly<Record<string, readonly TerminalInfo[]>>

The terminals per session id.

ui/src/terminal/testing/contract.ts:35

TerminalHostContractControlInterface#

Reads the backend and acts from outside.

TypeScript
interface TerminalHostContractControl
TerminalHostContractControl properties
NameTypeDescription
announce(sessionId: string) => void

The backend sends a session's full list (as after any change).

print(terminalId: string, data: string) => void

The terminal prints data: the backend sends it to the attached views, at the end of its history.

relink?() => void

The link to the backend drops and comes back. Absent: it never drops.

terminals() => TerminalInfo[]

Every terminal the backend holds now.

writes(terminalId: string) => string[]

The typing a terminal received, one entry per write.

ui/src/terminal/testing/contract.ts:45

TerminalHostHarnessInterface#

A host built over a backend, the backend's control, and how to tear them down.

TypeScript
interface TerminalHostHarness
TerminalHostHarness properties
NameTypeDescription
controlTerminalHostContractControl

Reads and acts on the backend.

hostTerminalHost

The host under test.

dispose?() => void

Closes connections and listeners after each test.

ui/src/terminal/testing/contract.ts:59

Types#

TerminalHostCapabilityType#

An optional TerminalHost member.

TypeScript
type TerminalHostCapability =
  | 'restart'
  | 'setHidden'
  | 'adoptDraft'
  | 'releaseDraft'
  | 'layouts'

ui/src/terminal/testing/contract.ts:24

TerminalHostHarnessFactoryType#

Builds a fresh host (and its backend) for one test.

TypeScript
type TerminalHostHarnessFactory = (backend: TerminalHostContractBackend) => TerminalHostHarness | Promise<TerminalHostHarness>

ui/src/terminal/testing/contract.ts:69