fix(sdk): transport 测试注释修正(sendBeacon 真实网络警示/退避区间)
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -88,7 +88,7 @@ describe("transport", () => {
|
||||
t.push({ event_id: "e2" });
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
|
||||
await vi.advanceTimersByTimeAsync(2000); // 第 1 次退避 500*2^1*jitter ∈ [1000,1400]
|
||||
await vi.advanceTimersByTimeAsync(2000); // 第 1 次退避 500*2^1*jitter ∈ [800,1200]
|
||||
expect(fetchMock).toHaveBeenCalledTimes(2);
|
||||
expect(fetchMock.mock.calls[1][1].body).toBe(fetchMock.mock.calls[0][1].body);
|
||||
expect((t as unknown as { retry: number }).retry).toBe(0);
|
||||
@@ -127,7 +127,7 @@ describe("transport", () => {
|
||||
t.push({ event_id: "e2" });
|
||||
expect(fetchMock).toHaveBeenCalledTimes(1);
|
||||
|
||||
await vi.advanceTimersByTimeAsync(2000); // 第 1 次重试(∈[1000,1400])后再失败
|
||||
await vi.advanceTimersByTimeAsync(2000); // 第 1 次重试(∈[800,1200])后再失败
|
||||
expect(fetchMock).toHaveBeenCalledTimes(2); // 初发 1 + 重试 1,共 2 次
|
||||
expect(t.dropped).toBe(2); // 按入批事件数计,而非按批计
|
||||
expect((t as unknown as { retry: number }).retry).toBe(0); // 归零供下批复用
|
||||
@@ -148,7 +148,7 @@ describe("transport", () => {
|
||||
});
|
||||
|
||||
it("flush(true) 走 sendBeacon(Blob/text/plain),不调 fetch", async () => {
|
||||
// happy-dom 无 navigator.sendBeacon——整对象替换并测后还原(unstubAllGlobals)
|
||||
// happy-dom 的 sendBeacon 会发真实网络请求,必须 stubGlobal 替换 navigator(不能只 spy)
|
||||
const beacon = vi.fn().mockReturnValue(true);
|
||||
vi.stubGlobal("navigator", { sendBeacon: beacon });
|
||||
const t = new Transport(mkCfg({ batchSize: 10 }));
|
||||
|
||||
Reference in New Issue
Block a user