Files
openclaw/extensions/browser/src/sdk-node-runtime.test.ts
2026-05-29 17:07:33 -04:00

19 lines
729 B
TypeScript

import { MAX_TIMER_TIMEOUT_MS } from "openclaw/plugin-sdk/number-runtime";
import { describe, expect, it, vi } from "vitest";
import { withTimeout } from "./sdk-node-runtime.js";
describe("withTimeout", () => {
it("caps oversized timeouts before arming the abort timer", async () => {
const timeoutSpy = vi
.spyOn(globalThis, "setTimeout")
.mockReturnValue(1 as unknown as ReturnType<typeof setTimeout>);
vi.spyOn(globalThis, "clearTimeout").mockImplementation(() => undefined);
await expect(
withTimeout(async () => "ok", Number.MAX_SAFE_INTEGER, "browser request"),
).resolves.toBe("ok");
expect(timeoutSpy).toHaveBeenCalledWith(expect.any(Function), MAX_TIMER_TIMEOUT_MS);
});
});