mirror of https://github.com/openclaw/openclaw.git
perf(test): fake abort timer and dedupe slack thread cases
This commit is contained in:
parent
29d3bb278f
commit
7648f6bb00
|
|
@ -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", () => {
|
||||
|
|
|
|||
|
|
@ -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({
|
||||
|
|
|
|||
Loading…
Reference in New Issue