smartstream/test/test.smartstream.ts

27 lines
822 B
TypeScript
Raw Normal View History

2023-11-01 13:16:58 +00:00
import { expect, tap } from '@push.rocks/tapbundle';
2023-11-03 20:32:24 +00:00
import { SmartDuplex } from '../ts/smartstream.classes.smartduplex.js'; // Adjust the import to your file structure
2023-11-01 13:16:58 +00:00
import * as smartrx from '@push.rocks/smartrx';
import * as fs from 'fs';
tap.test('should create a SmartStream from a Buffer', async () => {
const bufferData = Buffer.from('This is a test buffer');
2023-11-11 19:30:42 +00:00
const smartStream = SmartDuplex.fromBuffer(bufferData, {
handleBackpressure: false,
});
2023-11-01 13:16:58 +00:00
let receivedData = Buffer.alloc(0);
return new Promise<void>((resolve) => {
smartStream.on('data', (chunk: Buffer) => {
receivedData = Buffer.concat([receivedData, chunk]);
});
smartStream.on('end', () => {
expect(receivedData.toString()).toEqual(bufferData.toString());
resolve();
});
});
});
tap.start();