fix(sdk): flush前resume检查点预埋+onClose晚注册即触发+归属预留字段从快照展开
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -265,4 +265,33 @@ describe("PageSession / startPageSession", () => {
|
||||
t.flush();
|
||||
expect(flushedEvents("site-close").some((e) => e.event_name === "session_resume")).toBe(false);
|
||||
});
|
||||
|
||||
it("onClose 晚注册于 close 之后立即补触发;revive 后再 close 再次触发(bfcache 周期结算)", () => {
|
||||
const t = mkTransport("site-late-hook");
|
||||
const ps = startPageSession(t);
|
||||
ps.close(); // 先关闭(T7 初始化与 pagehide/路由切换竞态)
|
||||
const hook = vi.fn();
|
||||
ps.onClose(hook); // 晚注册:立即触发一次,不丢失本次结算时机
|
||||
expect(hook).toHaveBeenCalledTimes(1);
|
||||
|
||||
ps.revive(); // bfcache 复活:监听器不因 revive 清空
|
||||
ps.close();
|
||||
expect(hook).toHaveBeenCalledTimes(2); // 新周期的 close 再次触发
|
||||
});
|
||||
|
||||
it("flush 前检查点(Transport.flush 预埋):hidden 期间 flush 刷活 ctk_act 后仍能恢复", () => {
|
||||
const t = mkTransport("site-flushcp");
|
||||
const ps = startPageSession(t);
|
||||
const sid = ps.attribution().session_id;
|
||||
Object.defineProperty(document, "hidden", { value: true, configurable: true });
|
||||
vi.advanceTimersByTime(31 * 60_000);
|
||||
|
||||
t.flush(); // 信封 getSessionId() 会 touchActivity——若无 flush 前检查点,空闲被无限续期
|
||||
delete (document as { hidden?: boolean }).hidden;
|
||||
document.dispatchEvent(new Event("visibilitychange")); // 用户回前台
|
||||
expect(ps.attribution().session_id).not.toBe(sid); // 恢复未被抑制(OT01)
|
||||
|
||||
const sr = flushedEvents("site-flushcp").find((e) => e.event_name === "session_resume")!;
|
||||
expect(sr.properties.prev_session_id).toBe(sid);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user