Files
openclaw/extensions/inworld/voices-timeout.test.ts
chengzhichao-xydt a11449211a fix(inworld): add timeout to voices list request (#102965)
* fix(inworld): add timeout to voices list request

* refactor(inworld): reuse guarded timeout test helpers

* test(inworld): rely on harness timeout

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-07-11 01:35:25 -07:00

43 lines
1.2 KiB
TypeScript

import { withServer } from "openclaw/plugin-sdk/test-env";
import { afterEach, describe, expect, it, vi } from "vitest";
import { listInworldVoices } from "./tts.js";
describe("listInworldVoices live timeout", () => {
const originalFetch = globalThis.fetch;
afterEach(() => {
vi.unstubAllGlobals();
});
it(
"aborts a hanging voice list request within the configured timeout",
{ timeout: 2_000 },
async () => {
let requestCount = 0;
await withServer(
(request) => {
requestCount += 1;
request.resume();
},
async (baseUrl) => {
vi.stubGlobal(
"fetch",
vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {
return await originalFetch(`${baseUrl}/voices/v1/voices`, init);
}) as unknown as typeof globalThis.fetch,
);
await expect(
listInworldVoices({
apiKey: "test-key",
baseUrl: "https://custom.inworld.example.com",
timeoutMs: 250,
}),
).rejects.toThrow(/aborted|timeout|timed out/i);
expect(requestCount).toBe(1);
},
);
},
);
});