diff --git a/src/infra/abort-pattern.test.ts b/src/infra/abort-pattern.test.ts index 6e20d3ce2ba..1bcb7b5bf63 100644 --- a/src/infra/abort-pattern.test.ts +++ b/src/infra/abort-pattern.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, it } from "vitest"; +import { describe, expect, it, vi } from "vitest"; import { bindAbortRelay } from "../utils/fetch-timeout.js"; /** @@ -25,12 +25,17 @@ describe("abort pattern: .bind() vs arrow closure (#7174)", () => { }); it("bound abort works with setTimeout", async () => { - const controller = new AbortController(); - const timer = setTimeout(controller.abort.bind(controller), 10); - expect(controller.signal.aborted).toBe(false); - await new Promise((r) => setTimeout(r, 50)); - expect(controller.signal.aborted).toBe(true); - clearTimeout(timer); + vi.useFakeTimers(); + try { + const controller = new AbortController(); + const timer = setTimeout(controller.abort.bind(controller), 10); + expect(controller.signal.aborted).toBe(false); + await vi.advanceTimersByTimeAsync(10); + expect(controller.signal.aborted).toBe(true); + clearTimeout(timer); + } finally { + vi.useRealTimers(); + } }); it("bindAbortRelay() preserves default AbortError reason when used as event listener", () => { diff --git a/src/slack/monitor.test.ts b/src/slack/monitor.test.ts index 9a1e5e991d0..406b7f2ebac 100644 --- a/src/slack/monitor.test.ts +++ b/src/slack/monitor.test.ts @@ -61,29 +61,22 @@ describe("resolveSlackThreadTs", () => { const threadTs = "1234567890.123456"; const messageTs = "9999999999.999999"; + it("stays in incoming threads for all replyToMode values", () => { + for (const replyToMode of ["off", "first", "all"] as const) { + for (const hasReplied of [false, true]) { + expect( + resolveSlackThreadTs({ + replyToMode, + incomingThreadTs: threadTs, + messageTs, + hasReplied, + }), + ).toBe(threadTs); + } + } + }); + describe("replyToMode=off", () => { - it("returns incomingThreadTs when in a thread", () => { - expect( - resolveSlackThreadTs({ - replyToMode: "off", - incomingThreadTs: threadTs, - messageTs, - hasReplied: false, - }), - ).toBe(threadTs); - }); - - it("returns incomingThreadTs even after replies (stays in thread)", () => { - expect( - resolveSlackThreadTs({ - replyToMode: "off", - incomingThreadTs: threadTs, - messageTs, - hasReplied: true, - }), - ).toBe(threadTs); - }); - it("returns undefined when not in a thread", () => { expect( resolveSlackThreadTs({ @@ -97,17 +90,6 @@ describe("resolveSlackThreadTs", () => { }); describe("replyToMode=first", () => { - it("returns incomingThreadTs when in a thread (always stays threaded)", () => { - expect( - resolveSlackThreadTs({ - replyToMode: "first", - incomingThreadTs: threadTs, - messageTs, - hasReplied: false, - }), - ).toBe(threadTs); - }); - it("returns messageTs for first reply when not in a thread", () => { expect( resolveSlackThreadTs({ @@ -132,17 +114,6 @@ describe("resolveSlackThreadTs", () => { }); describe("replyToMode=all", () => { - it("returns incomingThreadTs when in a thread", () => { - expect( - resolveSlackThreadTs({ - replyToMode: "all", - incomingThreadTs: threadTs, - messageTs, - hasReplied: false, - }), - ).toBe(threadTs); - }); - it("returns messageTs when not in a thread (starts thread)", () => { expect( resolveSlackThreadTs({