Add market watch and match hub workflows
这个提交包含在:
29
server/_core/fetch.test.ts
普通文件
29
server/_core/fetch.test.ts
普通文件
@@ -0,0 +1,29 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { fetchWithTimeout } from "./fetch";
|
||||
|
||||
describe("fetchWithTimeout", () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it("retries timeout-like errors for allowed methods", async () => {
|
||||
const fetchMock = vi.fn()
|
||||
.mockRejectedValueOnce(new Error("Request timed out after 100ms"))
|
||||
.mockResolvedValueOnce(new Response("ok", { status: 200 }));
|
||||
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
|
||||
const response = await fetchWithTimeout("https://example.com", {
|
||||
method: "POST",
|
||||
}, {
|
||||
timeoutMs: 100,
|
||||
retries: 1,
|
||||
retryMethods: ["POST"],
|
||||
baseDelayMs: 1,
|
||||
});
|
||||
|
||||
expect(response.ok).toBe(true);
|
||||
expect(fetchMock).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
在新工单中引用
屏蔽一个用户