@@ -152,24 +152,30 @@ async function runTestCase(name: string, tempTmpDir: string, casesDir: string) {
152152 const cwd = npath . toPortablePath ( caseTmpDir ) ;
153153 for ( const command of steps . commands ) {
154154 debug ( 'running command: %s, cwd: %s, env: %o' , command , caseTmpDir , env ) ;
155- const outpuStreamPath = path . join ( caseTmpDir , 'output.log' ) ;
156- const outputStream = await open ( outpuStreamPath , 'w' ) ;
155+
156+ /// While `@yarnpkg/shell` supports capturing output via in-memory `Writable` streams,
157+ /// it seems not to have stable ordering of stdout/stderr chunks.
158+ /// To ensure stable ordering, we redirect outputs to a file instead.
159+ const outputStreamPath = path . join ( caseTmpDir , 'output.log' ) ;
160+ const outputStream = await open ( outputStreamPath , 'w' ) ;
157161
158162 const exitCode = await execute ( stripComments ( command ) , [ ] , {
159163 env,
160164 cwd,
161165 stdin : null ,
166+ // Declared to be `Writable` but `FileHandle` works too.
162167 stderr : outputStream as any ,
163168 stdout : outputStream as any ,
164169 glob : {
170+ // Disable glob expansion. Pass args like '--filter=*' as-is.
165171 isGlobPattern : ( ) => false ,
166172 match : async ( ) => [ ] ,
167173 } ,
168174 } ) ;
169175
170176 outputStream . close ( ) ;
171177
172- const output = readFileSync ( outpuStreamPath , 'utf-8' ) ;
178+ const output = readFileSync ( outputStreamPath , 'utf-8' ) ;
173179
174180 let commandLine = `> ${ command } ` ;
175181 if ( exitCode !== 0 ) {
0 commit comments