@@ -8,6 +8,7 @@ import { cpus, tmpdir } from 'node:os';
88import path from 'node:path' ;
99import { debuglog , parseArgs } from 'node:util' ;
1010
11+ import { setTimeout } from 'node:timers/promises' ;
1112import { isPassThroughEnv , replaceUnstableOutput } from './utils' ;
1213
1314const debug = debuglog ( 'vite-plus/snap-test' ) ;
@@ -159,34 +160,40 @@ async function runTestCase(name: string, tempTmpDir: string, casesDir: string) {
159160 const outputStreamPath = path . join ( caseTmpDir , 'output.log' ) ;
160161 const outputStream = await open ( outputStreamPath , 'w' ) ;
161162
162- const exitCode = await execute ( stripComments ( command ) , [ ] , {
163- env,
164- cwd,
165- stdin : null ,
166- // Declared to be `Writable` but `FileHandle` works too.
167- // @ts -expect-error
168- stderr : outputStream ,
169- // @ts -expect-error
170- stdout : outputStream ,
171- glob : {
172- // Disable glob expansion. Pass args like '--filter=*' as-is.
173- isGlobPattern : ( ) => false ,
174- match : async ( ) => [ ] ,
175- } ,
176- } ) ;
163+ const exitCode = await Promise . race ( [
164+ execute ( stripComments ( command ) , [ ] , {
165+ env,
166+ cwd,
167+ stdin : null ,
168+ // Declared to be `Writable` but `FileHandle` works too.
169+ // @ts -expect-error
170+ stderr : outputStream ,
171+ // @ts -expect-error
172+ stdout : outputStream ,
173+ glob : {
174+ // Disable glob expansion. Pass args like '--filter=*' as-is.
175+ isGlobPattern : ( ) => false ,
176+ match : async ( ) => [ ] ,
177+ } ,
178+ } ) ,
179+ setTimeout ( 30 * 1000 ) ,
180+ ] ) ;
177181
178182 await outputStream . close ( ) ;
179183
180184 const output = readFileSync ( outputStreamPath , 'utf-8' ) ;
181185
182186 let commandLine = `> ${ command } ` ;
183187 if ( exitCode !== 0 ) {
184- commandLine = `[${ exitCode } ]` + commandLine ;
188+ commandLine = ( exitCode === undefined ? '[timeout]' : `[${ exitCode } ]` ) + commandLine ;
185189 }
186190 newSnap . push ( commandLine ) ;
187191 if ( output . length > 0 ) {
188192 newSnap . push ( replaceUnstableOutput ( output , caseTmpDir ) ) ;
189193 }
194+ if ( exitCode === undefined ) {
195+ break ; // Stop executing further commands on timeout
196+ }
190197 }
191198 const newSnapContent = newSnap . join ( '\n' ) ;
192199
0 commit comments