Files
notification-elements-demo/node_modules/piscina/test/generics.ts
Giuliano Silvestro 5d0c9ec7eb Initial commit: notification-elements-demo app
Interactive Angular 19 demo for @sda/notification-elements-ui with
6 sections: Bell & Feed, Notification Center, Inbox, Comments &
Threads, Mention Input, and Full-Featured layout. Includes mock
data, dark mode toggle, and real-time event log.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 21:49:19 +10:00

43 lines
1.3 KiB
TypeScript

import { resolve } from 'path';
import Piscina from '..';
import { test } from 'tap';
test('Piscina<T , R> works', async ({ equal }) => {
const worker = new Piscina<string, number>({
filename: resolve(__dirname, 'fixtures/eval.js')
});
const result: number = await worker.run('Promise.resolve(42)');
equal(result, 42);
});
test('Piscina with no generic works', async ({ equal }) => {
const worker = new Piscina({
filename: resolve(__dirname, 'fixtures/eval.js')
});
const result = await worker.run('Promise.resolve("Hello, world!")');
equal(result, 'Hello, world!');
});
test('Piscina<T, R> typescript complains when invalid Task is supplied as wrong type', async ({ equal }) => {
const worker = new Piscina<string, number>({
filename: resolve(__dirname, 'fixtures/eval.js')
});
// @ts-expect-error complains due to invalid Task being number when expecting string
const result = await worker.run(42);
equal(result, 42);
});
test('Piscina<T, R> typescript complains when assigning Result to wrong type', async ({ equal }) => {
const worker = new Piscina<string, number>({
filename: resolve(__dirname, 'fixtures/eval.js')
});
// @ts-expect-error complains due to expecting a number but being assigned to a string
const result: string = await worker.run('Promise.resolve(42)');
equal(result, 42);
});