Skip to content
File

Blob: tests/worker/helpers/queues.ts

typescript24 lines
1import { afterEach, beforeEach, vi } from "vitest";
2 
3const QUEUE_SEND_RESPONSE = {
4 metadata: { metrics: { backlogCount: 0, backlogBytes: 0 } },
5} satisfies QueueSendResponse & QueueSendBatchResponse;
6 
7export function installNoopTasksQueue(env: Pick<Env, "TASKS_QUEUE">): void {
8 let restore: (() => void) | null = null;
9 
10 beforeEach(() => {
11 const send = vi.spyOn(env.TASKS_QUEUE, "send").mockResolvedValue(QUEUE_SEND_RESPONSE);
12 const sendBatch = vi.spyOn(env.TASKS_QUEUE, "sendBatch").mockResolvedValue(QUEUE_SEND_RESPONSE);
13 restore = () => {
14 send.mockRestore();
15 sendBatch.mockRestore();
16 };
17 });
18 
19 afterEach(() => {
20 restore?.();
21 restore = null;
22 });
23}