chore: Fix types in tests 3/N.

This commit is contained in:
cpojer
2026-02-17 10:50:22 +09:00
parent 3518554e23
commit 1406b28469
6 changed files with 145 additions and 75 deletions

View File

@@ -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);