Files
Tom Moor 6a6987ec2d perf: Faster mention suggestions (#14583)
* perf: Faster mention suggestions

Limit each section of suggestions.mention to 1s so a slow query does not
delay the others, debounce mention and link editor requests, ignore stale
responses, and use title search in the link editor.

* fix: Include presentation in the mention suggestion time limits

* test: Use a fixed name in the collection member name filter test
2026-11-13 22:37:49 -05:00

51 lines
1.2 KiB
TypeScript

import { withinTimeLimit } from "./timers";
describe("withinTimeLimit", () => {
it("should return the result when the function finishes in time", async () => {
const onTimeout = vi.fn();
const result = await withinTimeLimit(
async () => "done",
100,
"fallback",
onTimeout
);
expect(result).toEqual("done");
expect(onTimeout).not.toHaveBeenCalled();
});
it("should return the fallback when the function is too slow", async () => {
vi.useFakeTimers();
try {
const onTimeout = vi.fn();
const promise = withinTimeLimit(
() => new Promise<string>(() => undefined),
100,
"fallback",
onTimeout
);
await vi.advanceTimersByTimeAsync(100);
await expect(promise).resolves.toEqual("fallback");
expect(onTimeout).toHaveBeenCalledTimes(1);
} finally {
vi.useRealTimers();
}
});
it("should throw the error of a function that fails in time", async () => {
await expect(
withinTimeLimit(
async () => {
throw new Error("failed");
},
100,
"fallback"
)
).rejects.toThrow("failed");
});
});