diff --git a/tests/typetests/index.test.ts b/tests/typetests/index.test.ts index 3a1dd06..1747865 100644 --- a/tests/typetests/index.test.ts +++ b/tests/typetests/index.test.ts @@ -1,9 +1,10 @@ import { describe, expect, test } from "tstyche"; -import type { Token, WorkerTasks, AsyncMessage } from "../../src/workers.js"; +import type { Token, WorkerTasks, AsyncMessage, QueueingOptions } from "../../src/workers.js"; import { CancellationSource } from "../../src/cancellation/CancellationSource.js"; import { TaskCancelledError } from "../../src/cancellation/TaskCancelledError.js"; import { Queue } from "../../src/misc/Queue.js"; -import { AsyncWorker, type Enqueue, type EnqueueFn } from "../../src/workers/AsyncWorker.js"; +import type { Enqueue, EnqueueFn } from "../../src/workers/AsyncWorker.js"; +import { WorkItem } from "../../src/workers/WorkItem.js"; describe("Type Tests", () => { test("Token should be Int32Array", () => { @@ -86,3 +87,26 @@ describe("Type Tests", () => { expect(stringQueue.enqueue).type.not.toBeCallableWith({}); }); }); + +describe('Enqueue, EnqueueFn', () => { + type TestTasks = { + add: (args: { a: number; b: number }) => number; + greet: (args: { name: string }) => string; + noArgs: () => void; + }; + test("EnqueueFn should generate correct task functions.", () => { + expect>().type.toBeCallableWith({ a: 1, b: 2 }); + expect>().type.toBeCallableWith({ a: 1, b: 2 }, { cancellable: true }); + expect>().type.toBeCallableWith({ name: "Alice" }); + expect>().type.toBeCallableWith({ name: "Alice" }, { cancellable: true }); + expect>().type.toBeCallableWith(); + expect>().type.toBeCallableWith(undefined, { cancellable: true }); + }); + test("Enqueue should map task names to EnqueueFn correctly.", () => { + expect>().type.toBe<{ + add: (payload: { a: number; b: number }, options?: QueueingOptions) => WorkItem; + greet: (payload: { name: string }, options?: QueueingOptions) => WorkItem; + noArgs: (payload: void, options?: QueueingOptions) => WorkItem; + }>(); + }); +}); \ No newline at end of file