fix: normalize telegram fetch for long-polling

This commit is contained in:
Peter Steinberger
2026-01-24 21:58:42 +00:00
parent 30534c5c33
commit ac00065727
6 changed files with 24 additions and 94 deletions

View File

@@ -177,13 +177,11 @@ describe("createTelegramBot", () => {
expect(throttlerSpy).toHaveBeenCalledTimes(1);
expect(useSpy).toHaveBeenCalledWith("throttler");
});
it("forces native fetch only under Bun", () => {
it("uses wrapped fetch when global fetch is available", () => {
const originalFetch = globalThis.fetch;
const originalBun = (globalThis as { Bun?: unknown }).Bun;
const fetchSpy = vi.fn() as unknown as typeof fetch;
globalThis.fetch = fetchSpy;
try {
(globalThis as { Bun?: unknown }).Bun = {};
createTelegramBot({ token: "tok" });
const fetchImpl = resolveTelegramFetch();
expect(fetchImpl).toBeTypeOf("function");
@@ -194,33 +192,6 @@ describe("createTelegramBot", () => {
expect(clientFetch).not.toBe(fetchSpy);
} finally {
globalThis.fetch = originalFetch;
if (originalBun === undefined) {
delete (globalThis as { Bun?: unknown }).Bun;
} else {
(globalThis as { Bun?: unknown }).Bun = originalBun;
}
}
});
it("does not force native fetch on Node", () => {
const originalFetch = globalThis.fetch;
const originalBun = (globalThis as { Bun?: unknown }).Bun;
const fetchSpy = vi.fn() as unknown as typeof fetch;
globalThis.fetch = fetchSpy;
try {
if (originalBun !== undefined) {
delete (globalThis as { Bun?: unknown }).Bun;
}
createTelegramBot({ token: "tok" });
const fetchImpl = resolveTelegramFetch();
expect(fetchImpl).toBeUndefined();
expect(botCtorSpy).toHaveBeenCalledWith("tok", undefined);
} finally {
globalThis.fetch = originalFetch;
if (originalBun === undefined) {
delete (globalThis as { Bun?: unknown }).Bun;
} else {
(globalThis as { Bun?: unknown }).Bun = originalBun;
}
}
});
it("passes timeoutSeconds even without a custom fetch", () => {