From e1567434aeeba47305e4e84cfc427d2b37fb4af7 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 18 Mar 2026 12:31:06 +0000 Subject: [PATCH 1/2] test: add error path tests for WebSocketHelper handlers Co-authored-by: sebamar88 <4359231+sebamar88@users.noreply.github.com> --- tests/websocket-helper.test.ts | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/websocket-helper.test.ts b/tests/websocket-helper.test.ts index 13b9339..a0751b6 100644 --- a/tests/websocket-helper.test.ts +++ b/tests/websocket-helper.test.ts @@ -69,6 +69,28 @@ test("WebSocketHelper connects and sends heartbeat", async () => { wsh.close(); }); +test("WebSocketHelper handles non-Error objects thrown by handlers", async () => { + const wsh = new WebSocketHelper("ws://localhost"); + await wsh.connect(); + + let caughtError: Error | null = null; + wsh.onError((err) => { + caughtError = err; + }); + + wsh.on("string-error", () => { + throw "something went wrong"; + }); + + // @ts-expect-error - Test type override + wsh.ws._receive({ type: "string-error", data: {} }); + + assert.ok(caughtError instanceof Error); + assert.equal(caughtError?.message, "something went wrong"); + + wsh.close(); +}); + test("WebSocketHelper receives messages and notifies subscribers", async () => { const wsh = new WebSocketHelper("ws://localhost"); await wsh.connect(); @@ -283,3 +305,31 @@ test("WebSocketHelper notifyError ignores handler exceptions", async () => { wsh.close(); console.error = originalError; }); + +test("WebSocketHelper continues to next handler if one fails", async () => { + const wsh = new WebSocketHelper("ws://localhost"); + await wsh.connect(); + + let handler2Called = false; + let errorNotified = false; + + wsh.onError(() => { + errorNotified = true; + }); + + wsh.on("multi", () => { + throw new Error("First handler failed"); + }); + + wsh.on("multi", () => { + handler2Called = true; + }); + + // @ts-expect-error - Test type override + wsh.ws._receive({ type: "multi", data: { ok: true } }); + + assert.equal(errorNotified, true); + assert.equal(handler2Called, true); + + wsh.close(); +}); From 3193285e493a72ea6b0ebcdf67ad5f5ee3c352e0 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 19 Mar 2026 18:22:57 +0000 Subject: [PATCH 2/2] test: add error path tests for WebSocketHelper and fix CI type errors Co-authored-by: sebamar88 <4359231+sebamar88@users.noreply.github.com> --- src/cli/index.ts | 18 ++++++++++++++---- src/utils/helpers/CryptoUtils.ts | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/cli/index.ts b/src/cli/index.ts index 9010526..f9ec3ae 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -75,14 +75,19 @@ export async function runCli(argv: string[]): Promise { if (options.swagger) { await generateFromSwagger({ url: options.url }); } else if (options.type) { - await handleTypeGeneration(options); + await handleTypeGeneration(options as any); } else { // Simple fetch/curl behavior if --type is not present - await handleSimpleFetch(options); + await handleSimpleFetch(options as any); } } -async function handleTypeGeneration(options: any): Promise { +async function handleTypeGeneration(options: { + url: string; + method: HttpMethod; + body?: string; + headers: Record; +}): Promise { const url = new URL(options.url); const endpointName = url.pathname.split("/").filter(Boolean).pop() || "api"; @@ -104,7 +109,12 @@ async function handleTypeGeneration(options: any): Promise { }); } -async function handleSimpleFetch(options: any): Promise { +async function handleSimpleFetch(options: { + url: string; + method: HttpMethod; + body?: string; + headers: Record; +}): Promise { console.log(`\n📡 Fetching ${options.method} ${options.url}...`); try { const response = await fetch(options.url, { diff --git a/src/utils/helpers/CryptoUtils.ts b/src/utils/helpers/CryptoUtils.ts index 33624bb..beb9710 100644 --- a/src/utils/helpers/CryptoUtils.ts +++ b/src/utils/helpers/CryptoUtils.ts @@ -188,7 +188,7 @@ export class CryptoUtils { const encoder = new TextEncoder(); const key = await globalThis.crypto.subtle.importKey( "raw", - encoder.encode(secret), + encoder.encode(secret) as BufferSource, { name: "HMAC", hash: algorithm }, false, ["sign"]