52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import { expect, tap } from '@push.rocks/tapbundle';
|
|
import { createTransformFunction, createPassThrough, SmartDuplex, StreamWrapper } from '../ts/index.js';
|
|
|
|
// =============================================
|
|
// createTransformFunction
|
|
// =============================================
|
|
|
|
tap.test('createTransformFunction: should create a transform stream', async (tools) => {
|
|
const doubler = createTransformFunction<number, number>(async (n) => n * 2, { objectMode: true });
|
|
const results: number[] = [];
|
|
|
|
doubler.on('data', (chunk: number) => results.push(chunk));
|
|
|
|
const done = tools.defer();
|
|
doubler.on('end', () => {
|
|
expect(results).toContain(10);
|
|
expect(results).toContain(20);
|
|
expect(results).toContain(30);
|
|
done.resolve();
|
|
});
|
|
|
|
doubler.write(5);
|
|
doubler.write(10);
|
|
doubler.write(15);
|
|
doubler.end();
|
|
await done.promise;
|
|
});
|
|
|
|
// =============================================
|
|
// createPassThrough
|
|
// =============================================
|
|
|
|
tap.test('createPassThrough: should pass data through unchanged', async (tools) => {
|
|
const passThrough = createPassThrough();
|
|
const results: string[] = [];
|
|
|
|
passThrough.on('data', (chunk: string) => results.push(chunk));
|
|
|
|
const done = tools.defer();
|
|
passThrough.on('end', () => {
|
|
expect(results).toEqual(['hello', 'world']);
|
|
done.resolve();
|
|
});
|
|
|
|
passThrough.write('hello');
|
|
passThrough.write('world');
|
|
passThrough.end();
|
|
await done.promise;
|
|
});
|
|
|
|
export default tap.start();
|