diff --git a/packages/vitest/src/typecheck/typechecker.ts b/packages/vitest/src/typecheck/typechecker.ts index b43191547..55bda5fb1 100644 --- a/packages/vitest/src/typecheck/typechecker.ts +++ b/packages/vitest/src/typecheck/typechecker.ts @@ -401,13 +401,16 @@ export class Typechecker { child.process?.off('error', onError) clearTimeout(timeout) if (process.platform === 'win32') { - // on Windows, the process might be spawned but fail to start - // we wait for a potential error here. if "close" event didn't trigger, - // we resolve the promise - winTimeout = setTimeout(() => { - resolved = true - resolve({ result: child }) - }, 200) + // on Windows, the process might be spawned but fail to start, + // so we wait for the "close" event instead of resolving right away. + // `start` awaits the process anyway; the watch process never exits, + // so resolve it after a grace period + if (watch) { + winTimeout = setTimeout(() => { + resolved = true + resolve({ result: child }) + }, 200) + } } else { resolved = true @@ -420,6 +423,11 @@ export class Typechecker { if (code != null && code !== 0 && !dataReceived) { onError(new Error(`The ${typecheck.checker} command exited with code ${code}.`)) } + else if (!resolved) { + clearTimeout(winTimeout) + resolved = true + resolve({ result: child }) + } }) } child.process.once('error', onError)