Skip to content

Commit

Permalink
fix: speed-up exit when stopping watch (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
Demivan committed Jan 20, 2022
1 parent 9a7458a commit ae17bb9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/vitest/src/node/core.ts
Expand Up @@ -350,13 +350,15 @@ export class Vitest {
return this.closingPromise
}

async exit() {
async exit(force = false) {
setTimeout(() => {
console.warn(`close timed out after ${CLOSE_TIMEOUT}ms`)
process.exit()
}, CLOSE_TIMEOUT).unref()

await this.close()
if (force)
process.exit()
}

async report<T extends keyof Reporter>(name: T, ...args: ArgumentsType<Reporter[T]>) {
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/node/stdin.ts
Expand Up @@ -24,7 +24,7 @@ export function registerConsoleShortcuts(ctx: Vitest) {
process.stdin.on('keypress', (str: string, key: any) => {
// ctrl-c or esc
if (str === '\x03' || str === '\x1B' || (key && key.ctrl && key.name === 'c'))
return ctx.exit()
return ctx.exit(true)

// is running, ignore keypress
if (ctx.runningPromise)
Expand All @@ -43,7 +43,7 @@ export function registerConsoleShortcuts(ctx: Vitest) {
return ctx.rerunFiles(undefined, 'rerun all')
// quit
if (name === 'q')
return ctx.exit()
return ctx.exit(true)

// TODO: add more commands
})
Expand Down

0 comments on commit ae17bb9

Please sign in to comment.