feat(core-testing): RecordingJobQueue

Adds RecordingJobQueue implementing IJobQueue for use in unit tests.
Records all enqueue calls with taskSlug/input/options and returns
synthetic incrementing jobIds.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-08 12:04:22 +02:00
parent 05f0b02856
commit 590b92f190
5 changed files with 42 additions and 0 deletions

View File

@@ -21,6 +21,7 @@
"test": "vitest run"
},
"dependencies": {
"@repo/core-shared": "workspace:*",
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/react": "^16.0.0",
"@testing-library/user-event": "^14.5.0",

View File

@@ -1,2 +1,3 @@
export { RecordingTracer, type RecordedSpan } from "./recording-tracer";
export { RecordingLogger, type RecordedCapture } from "./recording-logger";
export { RecordingJobQueue } from "./recording-job-queue";

View File

@@ -0,0 +1,23 @@
import { describe, it, expect } from "vitest";
import { RecordingJobQueue } from "@/instrumentation/recording-job-queue";
describe("RecordingJobQueue", () => {
it("records every enqueue call", async () => {
const queue = new RecordingJobQueue();
const future = new Date("2030-01-01");
await queue.enqueue("a.task", { x: 1 });
await queue.enqueue("b.task", { y: 2 }, { runAt: future });
expect(queue.enqueued).toEqual([
{ taskSlug: "a.task", input: { x: 1 }, options: undefined },
{ taskSlug: "b.task", input: { y: 2 }, options: { runAt: future } },
]);
});
it("returns a synthetic jobId per call", async () => {
const queue = new RecordingJobQueue();
const a = await queue.enqueue("a", {});
const b = await queue.enqueue("b", {});
expect(a.jobId).toBe("recording-1");
expect(b.jobId).toBe("recording-2");
});
});

View File

@@ -0,0 +1,14 @@
import type { IJobQueue } from "@repo/core-shared/jobs";
export class RecordingJobQueue implements IJobQueue {
readonly enqueued: { taskSlug: string; input: unknown; options?: { runAt?: Date } }[] = [];
async enqueue<T>(
taskSlug: string,
input: T,
options?: { runAt?: Date },
): Promise<{ jobId: string }> {
this.enqueued.push({ taskSlug, input, options });
return { jobId: `recording-${this.enqueued.length}` };
}
}