@@ -23,6 +23,7 @@ import {
23
23
getReadWriteSubprocess ,
24
24
} from '../helpers/convert.js' ;
25
25
import { foobarString } from '../helpers/input.js' ;
26
+ import { majorNodeVersion } from '../helpers/node-version.js' ;
26
27
import { prematureClose , fullStdio , fullReadableStdio } from '../helpers/stdio.js' ;
27
28
import { defaultHighWaterMark } from '../helpers/stream.js' ;
28
29
@@ -148,13 +149,21 @@ test('.duplex() can pipe to errored stream with Stream.pipeline()', async t => {
148
149
const cause = new Error ( 'test' ) ;
149
150
outputStream . destroy ( cause ) ;
150
151
151
- await assertPromiseError ( t , pipeline ( inputStream , stream , outputStream ) , cause ) ;
152
- await t . throwsAsync ( finishedStream ( stream ) ) ;
153
-
154
- await assertStreamError ( t , inputStream , cause ) ;
155
- const error = await assertStreamError ( t , stream , cause ) ;
156
- await assertStreamReadError ( t , outputStream , cause ) ;
157
- await assertSubprocessError ( t , subprocess , { cause : error } ) ;
152
+ // Node 23 does not allow calling `stream.pipeline()` with an already errored stream
153
+ if ( majorNodeVersion >= 23 ) {
154
+ outputStream . on ( 'error' , ( ) => { } ) ;
155
+ stream . on ( 'error' , ( ) => { } ) ;
156
+ await t . throwsAsync ( pipeline ( stream , outputStream ) , { code : 'ERR_STREAM_UNABLE_TO_PIPE' } ) ;
157
+ stream . end ( ) ;
158
+ } else {
159
+ await assertPromiseError ( t , pipeline ( inputStream , stream , outputStream ) , cause ) ;
160
+ await t . throwsAsync ( finishedStream ( stream ) ) ;
161
+
162
+ await assertStreamError ( t , inputStream , cause ) ;
163
+ const error = await assertStreamError ( t , stream , cause ) ;
164
+ await assertStreamReadError ( t , outputStream , cause ) ;
165
+ await assertSubprocessError ( t , subprocess , { cause : error } ) ;
166
+ }
158
167
} ) ;
159
168
160
169
test ( '.duplex() can be piped to errored stream with Stream.pipeline()' , async t => {
0 commit comments