/** * Messages exchanged between the browser and `@wdio/browser-runner`. * * The browser talks to the runner over the Vite websocket (`wdio:workerMessage`). * Request/response pairs that need the Node worker are forwarded with a * communicator routing id that is separate from the id inside `value` (that * one correlates a promise in the browser). * * `coverageMap` and `customCommand` share this enum for historic reasons but * travel on worker `process.send`, not on the browser channel. * * Numeric values are the on-wire `type` discriminant and must stay stable. */ export declare enum MESSAGE_TYPES { /** * @wdio/browser-runner messages */ consoleMessage = 0, commandRequestMessage = 1, commandResponseMessage = 2, hookTriggerMessage = 3, hookResultMessage = 4, expectRequestMessage = 5, expectResponseMessage = 6, expectMatchersRequest = 7, expectMatchersResponse = 8, coverageMap = 9, customCommand = 10, initiateBrowserStateRequest = 11, initiateBrowserStateResponse = 12, browserTestResult = 13 } export declare const BROWSER_TO_RUNNER_TYPES: readonly [MESSAGE_TYPES.consoleMessage, MESSAGE_TYPES.commandRequestMessage, MESSAGE_TYPES.hookTriggerMessage, MESSAGE_TYPES.expectRequestMessage, MESSAGE_TYPES.expectMatchersRequest, MESSAGE_TYPES.initiateBrowserStateRequest, MESSAGE_TYPES.browserTestResult]; export declare const RUNNER_TO_BROWSER_TYPES: readonly [MESSAGE_TYPES.commandResponseMessage, MESSAGE_TYPES.hookResultMessage, MESSAGE_TYPES.expectResponseMessage, MESSAGE_TYPES.expectMatchersResponse, MESSAGE_TYPES.initiateBrowserStateResponse]; /** * Browser messages that need a reply from the worker. The communicator stores * the originating Vite client under a routing id until `workerResponse` arrives. * Console output and the final test report are forwarded without that bookkeeping. */ export declare const BROWSER_REQUEST_TYPES: readonly [MESSAGE_TYPES.commandRequestMessage, MESSAGE_TYPES.hookTriggerMessage, MESSAGE_TYPES.expectRequestMessage, MESSAGE_TYPES.expectMatchersRequest]; export declare const WORKER_PROCESS_EVENT_TYPES: readonly [MESSAGE_TYPES.coverageMap, MESSAGE_TYPES.customCommand]; export type BrowserToRunnerType = typeof BROWSER_TO_RUNNER_TYPES[number]; export type RunnerToBrowserType = typeof RUNNER_TO_BROWSER_TYPES[number]; export type BrowserRequestType = typeof BROWSER_REQUEST_TYPES[number]; export type BrowserChannelType = BrowserToRunnerType | RunnerToBrowserType; export type WorkerProcessEventType = typeof WORKER_PROCESS_EVENT_TYPES[number]; /** * Error fields that survive `JSON.stringify` / Node IPC. A live `Error` * instance does not. */ export interface ChannelError { name?: string; message?: string; stack?: string; } export interface ConsoleEvent { name: 'consoleEvent'; type: 'log' | 'info' | 'warn' | 'debug' | 'error'; args: unknown[]; cid: string; } export interface ExpectMatchersRequest { cid?: string; } export interface ExpectMatchersResponse { matchers: string[]; } /** * Mocha reporter event as produced by `@wdio/mocha-framework`'s `formatMessage`. * Fields are optional because not every Mocha event populates the full shape. */ export interface BrowserTestEvent { type: string; title?: string; fullTitle?: string; pending?: boolean; passed?: boolean; file?: string; duration?: number; parent?: string; currentTest?: string; error?: ChannelError & { type?: string; expected?: unknown; actual?: unknown; }; context?: unknown; body?: string; cid?: string; specs?: string[]; uid?: string; } export interface BrowserTestResults { failures: number; events: BrowserTestEvent[]; } export interface CustomCommandEvent { commandName: string; cid: string; } /** * Istanbul's `window.__coverage__` map. Structural so this package does not * depend on istanbul. */ export type CoverageMapPayload = Record; export interface BrowserStateRequest { cid: string; } export interface BrowserState { customCommands: string[]; } export interface HookTriggerEvent { id: number; cid: string; name: string; args: unknown[]; } export interface HookResultEvent { id: number; error?: ChannelError; } export interface CommandRequestEvent { id: number; cid: string; commandName: string; args: unknown[]; scope?: string; } export interface CommandResponseEvent { id: number; result?: unknown; /** * The kind of `result` when it is a mock or a browsing context. JSON drops the * `wdio.kind` brand (see `@wdio/utils` `kind.ts`), so the page sets it again. * An element or an element list is not in this list: it is sent as element * references, which are not loaded elements and must not get the brand. */ kind?: 'mock' | 'browsing-context'; error?: ChannelError; } export interface ExpectRequestEvent { id: number; cid: string; matcherName: string; /** * this should be `MatcherState` from `expect` but don't want to introduce * this as a dependency to this package, therefore keep it as `any` for now */ scope: any; args: unknown[]; element?: any | any[]; /** * The kind of `element`, or `undefined` for a copy of an element list * (`WebdriverIO.Element[]`). JSON drops the properties of a list, so without * it an element list arrives as a plain array. */ elementKind?: 'element' | 'element-array'; context?: unknown; /** * propagate error stack for inline snapshots */ errorStack?: string; } export interface ExpectResponseEvent { id: number; pass: boolean; message: string; } export interface BrowserChannelValue { [MESSAGE_TYPES.consoleMessage]: ConsoleEvent; [MESSAGE_TYPES.commandRequestMessage]: CommandRequestEvent; [MESSAGE_TYPES.commandResponseMessage]: CommandResponseEvent; [MESSAGE_TYPES.hookTriggerMessage]: HookTriggerEvent; [MESSAGE_TYPES.hookResultMessage]: HookResultEvent; [MESSAGE_TYPES.expectRequestMessage]: ExpectRequestEvent; [MESSAGE_TYPES.expectResponseMessage]: ExpectResponseEvent; [MESSAGE_TYPES.expectMatchersRequest]: ExpectMatchersRequest; [MESSAGE_TYPES.expectMatchersResponse]: ExpectMatchersResponse; [MESSAGE_TYPES.initiateBrowserStateRequest]: BrowserStateRequest; [MESSAGE_TYPES.initiateBrowserStateResponse]: BrowserState; [MESSAGE_TYPES.browserTestResult]: BrowserTestResults; } export interface WorkerProcessEventValue { [MESSAGE_TYPES.coverageMap]: CoverageMapPayload; [MESSAGE_TYPES.customCommand]: CustomCommandEvent; } export type BrowserChannelMessage = T extends any ? { type: T; value: BrowserChannelValue[T]; } : never; export type AnyBrowserToRunnerMessage = BrowserChannelMessage; export type AnyRunnerToBrowserMessage = BrowserChannelMessage; export type AnyBrowserChannelMessage = BrowserChannelMessage; /** * Every `MESSAGE_TYPES` payload, including worker-process events. * Kept so existing `Workers.SocketMessageValue` imports still resolve. */ export type SocketMessageValue = BrowserChannelValue & WorkerProcessEventValue; /** * Discriminated message for one `MESSAGE_TYPES` member. * Kept so existing `Workers.SocketMessagePayload<...>` imports still resolve. */ export type SocketMessagePayload = T extends any ? { type: T; value: SocketMessageValue[T]; } : never; /** * Historical union of every `MESSAGE_TYPES` payload. Prefer * `AnyBrowserToRunnerMessage` or `AnyRunnerToBrowserMessage` when the * direction is known. */ export type SocketMessage = SocketMessagePayload; export type WorkerProcessEvent = T extends any ? { type: T; value: WorkerProcessEventValue[T]; } : never; export type BrowserChannelRoute = { kind: 'drop'; } | { kind: 'browserState'; cid: string; } | { kind: 'event'; message: BrowserChannelMessage; } | { kind: 'request'; message: BrowserChannelMessage; }; export declare function browserChannelMessage(type: T, value: BrowserChannelValue[T]): BrowserChannelMessage; export declare function workerProcessEvent(type: T, value: WorkerProcessEventValue[T]): WorkerProcessEvent; export declare function isBrowserChannelMessage(message: unknown, type: T): message is BrowserChannelMessage; export declare function isWorkerProcessEvent(message: unknown, type: T): message is WorkerProcessEvent; /** * Validate an untrusted Vite websocket payload from the browser. * Returns `undefined` when the payload is not a browser → runner message. */ export declare function parseBrowserToRunnerMessage(data: unknown): AnyBrowserToRunnerMessage | undefined; /** * Validate an untrusted Vite websocket payload from the runner. * Returns `undefined` when the payload is not a runner → browser message. */ export declare function parseRunnerToBrowserMessage(data: unknown): AnyRunnerToBrowserMessage | undefined; /** * Classify a browser → runner payload so the communicator can respond locally, * forward a one-way event, or track a request until the worker replies. */ export declare function routeBrowserToRunnerMessage(data: unknown): BrowserChannelRoute; //# sourceMappingURL=BrowserChannel.d.ts.map