Skip to content

Commit fce5a89

Browse files
committed
test: add stream-utils test suit
1 parent 750b684 commit fce5a89

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

packages/stream-utils/src/index.spec.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
import {
99
toArray,
1010
mergeReadables,
11-
splitStream
11+
splitStream,
12+
firstFromStream
1213
} from './index.js'
1314

1415
function stream(id: string, time: number) {
@@ -52,4 +53,24 @@ describe('stream-utils', () => {
5253
])
5354
})
5455
})
56+
57+
describe('firstFromStream', () => {
58+
it('should return the first element', async () => {
59+
const stream = Readable.from([
60+
'1 2',
61+
' 3',
62+
' 4 5 6'
63+
])
64+
const result = await firstFromStream(stream)
65+
66+
expect(result).toEqual('1 2')
67+
})
68+
69+
it('should return null if the stream is empty', async () => {
70+
const stream = Readable.from([])
71+
const result = await firstFromStream(stream)
72+
73+
expect(result).toEqual(null)
74+
})
75+
})
5576
})

0 commit comments

Comments
 (0)