-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
read-stream.test.ts
50 lines (37 loc) · 1.2 KB
/
read-stream.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { PassThrough } from 'node:stream';
import { readStream } from './read-stream.js';
describe('stream-to-data', () => {
test('source without encoding', async () => {
const source = new PassThrough();
const promise = readStream(source);
source.write('foo');
source.write('bar');
source.end();
const buffer = await promise;
expect(buffer.toString()).toBe('foobar');
});
test('source with utf8 encoding', async () => {
const source = new PassThrough({ encoding: 'utf8' });
const promise = readStream(source);
source.write('foo');
source.write('bar');
source.end();
const buffer = await promise;
expect(buffer.toString()).toBe('foobar');
});
test('source in object mode', async () => {
const source = new PassThrough({ objectMode: true });
const promise = readStream(source);
source.write({ foo: true });
source.end();
await expect(promise).rejects.toBeInstanceOf(Error);
});
test('output encoding', async () => {
const source = new PassThrough();
const promise = readStream(source, 'utf8');
source.write('foo');
source.write('bar');
source.end();
await expect(promise).resolves.toBe('foobar');
});
});