mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 05:12:43 +00:00
chore: Fix types in tests 3/N.
This commit is contained in:
@@ -296,9 +296,20 @@ export async function occupyPort(): Promise<{
|
||||
});
|
||||
}
|
||||
|
||||
export function onceMessage<T = unknown>(
|
||||
type GatewayTestMessage = {
|
||||
type?: string;
|
||||
id?: string;
|
||||
ok?: boolean;
|
||||
event?: string;
|
||||
payload?: Record<string, unknown> | null;
|
||||
seq?: number;
|
||||
stateVersion?: Record<string, unknown>;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
|
||||
export function onceMessage<T extends GatewayTestMessage = GatewayTestMessage>(
|
||||
ws: WebSocket,
|
||||
filter: (obj: unknown) => boolean,
|
||||
filter: (obj: T) => boolean,
|
||||
// Full-suite runs can saturate the event loop (581+ files). Keep this high
|
||||
// enough to avoid flaky RPC timeouts, but still fail fast when a response
|
||||
// never arrives.
|
||||
@@ -312,12 +323,12 @@ export function onceMessage<T = unknown>(
|
||||
reject(new Error(`closed ${code}: ${reason.toString()}`));
|
||||
};
|
||||
const handler = (data: WebSocket.RawData) => {
|
||||
const obj = JSON.parse(rawDataToString(data));
|
||||
const obj = JSON.parse(rawDataToString(data)) as T;
|
||||
if (filter(obj)) {
|
||||
clearTimeout(timer);
|
||||
ws.off("message", handler);
|
||||
ws.off("close", closeHandler);
|
||||
resolve(obj as T);
|
||||
resolve(obj);
|
||||
}
|
||||
};
|
||||
ws.on("message", handler);
|
||||
|
||||
Reference in New Issue
Block a user