33
44const common = require ( '../common' ) ;
55const assert = require ( 'assert' ) ;
6+ const { Writable } = require ( 'stream' ) ;
67const {
7- from, fromSync, pull, pullSync, pipeTo,
8+ from, fromSync, pull, pullSync, pipeTo, fromWritable ,
89 push, duplex, broadcast, Broadcast, share, shareSync,
910 Share, SyncShare,
1011 bytes, bytesSync, text, textSync,
@@ -42,6 +43,19 @@ assert.throws(() => push({ signal: {} }), { code: 'ERR_INVALID_ARG_TYPE' });
4243assert . throws ( ( ) => push ( 42 , { } ) , { code : 'ERR_INVALID_ARG_TYPE' } ) ;
4344assert . throws ( ( ) => push ( 'bad' , { } ) , { code : 'ERR_INVALID_ARG_TYPE' } ) ;
4445
46+ // Writer options.signal must be AbortSignal
47+ {
48+ const { writer } = push ( ) ;
49+ const badOptions = { signal : 'bad' } ;
50+ assert . throws ( ( ) => writer . write ( 'a' , badOptions ) ,
51+ { code : 'ERR_INVALID_ARG_TYPE' } ) ;
52+ assert . throws ( ( ) => writer . writev ( [ 'b' ] , badOptions ) ,
53+ { code : 'ERR_INVALID_ARG_TYPE' } ) ;
54+ assert . throws ( ( ) => writer . end ( badOptions ) ,
55+ { code : 'ERR_INVALID_ARG_TYPE' } ) ;
56+ writer . endSync ( ) ;
57+ }
58+
4559// Writer.writev requires array
4660{
4761 const { writer } = push ( ) ;
@@ -147,6 +161,19 @@ assert.throws(() => broadcast({ highWaterMark: Number.MAX_SAFE_INTEGER + 1 }),
147161assert . throws ( ( ) => broadcast ( { signal : { } } ) , { code : 'ERR_INVALID_ARG_TYPE' } ) ;
148162assert . throws ( ( ) => broadcast ( { backpressure : 'bad' } ) , { code : 'ERR_INVALID_ARG_VALUE' } ) ;
149163
164+ // BroadcastWriter options.signal must be AbortSignal
165+ {
166+ const { writer } = broadcast ( ) ;
167+ const badOptions = { signal : 'bad' } ;
168+ assert . throws ( ( ) => writer . write ( 'a' , badOptions ) ,
169+ { code : 'ERR_INVALID_ARG_TYPE' } ) ;
170+ assert . throws ( ( ) => writer . writev ( [ 'b' ] , badOptions ) ,
171+ { code : 'ERR_INVALID_ARG_TYPE' } ) ;
172+ assert . throws ( ( ) => writer . end ( badOptions ) ,
173+ { code : 'ERR_INVALID_ARG_TYPE' } ) ;
174+ writer . endSync ( ) ;
175+ }
176+
150177// BroadcastWriter.writev requires array
151178{
152179 const { writer } = broadcast ( ) ;
@@ -160,6 +187,24 @@ assert.throws(() => broadcast({ backpressure: 'bad' }), { code: 'ERR_INVALID_ARG
160187// Broadcast.from rejects non-streamable input
161188assert . throws ( ( ) => Broadcast . from ( 42 ) , { code : 'ERR_INVALID_ARG_TYPE' } ) ;
162189
190+ // fromWritable Writer options.signal must be AbortSignal
191+ {
192+ const writable = new Writable ( {
193+ write ( chunk , encoding , callback ) {
194+ callback ( ) ;
195+ } ,
196+ } ) ;
197+ const writer = fromWritable ( writable ) ;
198+ const badOptions = { signal : 'bad' } ;
199+ assert . throws ( ( ) => writer . write ( 'a' , badOptions ) ,
200+ { code : 'ERR_INVALID_ARG_TYPE' } ) ;
201+ assert . throws ( ( ) => writer . writev ( [ 'b' ] , badOptions ) ,
202+ { code : 'ERR_INVALID_ARG_TYPE' } ) ;
203+ assert . throws ( ( ) => writer . end ( badOptions ) ,
204+ { code : 'ERR_INVALID_ARG_TYPE' } ) ;
205+ writable . destroy ( ) ;
206+ }
207+
163208// =============================================================================
164209// share() / shareSync() validation
165210// =============================================================================
0 commit comments