Skip to content

Commit 461e76f

Browse files
committed
fix: don't hang if Vitest failed to start
Fixes #362
1 parent f635c92 commit 461e76f

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/api.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ async function createChildVitestProcess(showWarning: boolean, meta: VitestPackag
266266
cwd: pnp ? dirname(pnp) : undefined,
267267
},
268268
)
269+
270+
vitest.stdout?.on('data', d => log.worker('info', d.toString()))
271+
vitest.stderr?.on('data', d => log.worker('error', d.toString()))
272+
269273
return new Promise<ChildProcess>((resolve, reject) => {
270274
function ready(message: any) {
271275
if (message.type === 'debug')
@@ -301,17 +305,24 @@ async function createChildVitestProcess(showWarning: boolean, meta: VitestPackag
301305
}
302306
vitest.off('error', error)
303307
vitest.off('message', ready)
308+
vitest.off('exit', exit)
304309
}
305310

306311
function error(err: Error) {
307312
log.error('[API]', err)
308313
reject(err)
309314
vitest.off('error', error)
310315
vitest.off('message', ready)
316+
vitest.off('exit', exit)
317+
}
318+
319+
function exit(code: number) {
320+
reject(new Error(`Vitest process exited with code ${code}`))
311321
}
312322

313323
vitest.on('error', error)
314324
vitest.on('message', ready)
325+
vitest.on('exit', exit)
315326
vitest.once('spawn', () => {
316327
const runnerOptions: WorkerRunnerOptions = {
317328
type: 'init',
@@ -339,9 +350,6 @@ export async function createVitestProcess(showWarning: boolean, packages: Vitest
339350

340351
log.info('[API]', `Vitest process ${vitest.pid} created`)
341352

342-
vitest.stdout?.on('data', d => log.worker('info', d.toString()))
343-
vitest.stderr?.on('data', d => log.worker('error', d.toString()))
344-
345353
const { handlers, api } = createVitestRpc(vitest)
346354

347355
return {

0 commit comments

Comments
 (0)