From cd51a3aca2a1fdc3dd32e88ec0dfeac1227eb8b3 Mon Sep 17 00:00:00 2001 From: AriPerkkio Date: Wed, 21 Jun 2023 11:35:56 +0300 Subject: [PATCH] fix: CTRL+c terminate run --- packages/vitest/src/node/cli-api.ts | 4 +--- packages/vitest/src/node/stdin.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/vitest/src/node/cli-api.ts b/packages/vitest/src/node/cli-api.ts index 84b280f79b1d..d68d0306a9ad 100644 --- a/packages/vitest/src/node/cli-api.ts +++ b/packages/vitest/src/node/cli-api.ts @@ -87,10 +87,8 @@ export async function startVitest( return ctx } - if (process.stdin.isTTY && ctx.config.watch) + if (process.stdin.isTTY) registerConsoleShortcuts(ctx) - else - process.on('SIGINT', () => ctx.cancelCurrentRun('keyboard-input')) ctx.onServerRestart((reason) => { ctx.report('onServerRestart', reason) diff --git a/packages/vitest/src/node/stdin.ts b/packages/vitest/src/node/stdin.ts index 9bc3485125dd..460d42235ad6 100644 --- a/packages/vitest/src/node/stdin.ts +++ b/packages/vitest/src/node/stdin.ts @@ -32,6 +32,10 @@ export function registerConsoleShortcuts(ctx: Vitest) { // If cancelling takes long and key is pressed multiple times, exit forcefully. if (str === '\x03' || str === '\x1B' || (key && key.ctrl && key.name === 'c')) { if (!ctx.isCancelling) { + ctx.logger.logUpdate.clear() + ctx.logger.log(c.red('Cancelling test run. Press CTRL+c again to exit forcefully.\n')) + process.exitCode = 130 + await ctx.cancelCurrentRun('keyboard-input') await ctx.runningPromise } @@ -45,6 +49,10 @@ export function registerConsoleShortcuts(ctx: Vitest) { return } + // Other keys are for watch mode only + if (!ctx.config.watch) + return + const name = key?.name if (ctx.runningPromise) {