release: WRNexusJS 0.3.0

This commit is contained in:
2026-07-22 17:29:08 +05:30
parent 13dfa31d19
commit 07d8fb59d6
145 changed files with 9664 additions and 3881 deletions
+35 -1
View File
@@ -1,5 +1,5 @@
import { test, expect } from "bun:test";
import { createQueue } from "../src/index.ts";
import { createQueue, cronToInterval, defineWorkflow } from "../src/index.ts";
test("processes a job", async () => {
const queue = createQueue();
@@ -104,3 +104,37 @@ test("drains independent due jobs concurrently", async () => {
releases.forEach((release) => release());
expect(await draining).toBe(2);
});
test("prioritizes due jobs and respects concurrency", async () => {
const queue = createQueue({ concurrency: 1 });
const order: string[] = [];
queue.process<string>("work", (job) => {
order.push(job.data);
});
await queue.add("work", "low", { priority: 1 });
await queue.add("work", "high", { priority: 10 });
expect(await queue.drain()).toBe(1);
expect(order).toEqual(["high"]);
expect(queue.size()).toBe(1);
});
test("deduplicates, lists and cancels queued work", async () => {
const queue = createQueue();
const first = await queue.add("sync", { id: 1 }, { idempotencyKey: "customer:1" });
const second = await queue.add("sync", { id: 2 }, { idempotencyKey: "customer:1" });
expect(second.id).toBe(first.id);
expect(queue.list("sync")).toHaveLength(1);
expect(queue.get(first.id)?.data).toEqual({ id: 1 });
expect(queue.cancel(first.id)).toBe(true);
expect(queue.cancel(first.id)).toBe(false);
});
test("runs typed workflows and parses supported cron expressions", async () => {
const workflow = defineWorkflow<number>("double-and-label", [
{ name: "double", run: (value: number) => value * 2 },
{ name: "label", run: (value: number) => `value:${value}` },
]);
expect(await workflow.run(5)).toBe("value:10");
expect(cronToInterval("@hourly")).toBe(3_600_000);
expect(cronToInterval("*/5 * * * *")).toBe(300_000);
});