File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
packages/stream-utils/src Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change 88import {
99 toArray ,
1010 mergeReadables ,
11- splitStream
11+ splitStream ,
12+ firstFromStream
1213} from './index.js'
1314
1415function 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} )
You can’t perform that action at this time.
0 commit comments