Skip to content

Commit fa6637d

Browse files
authoredJun 27, 2023
fix: CTRL+C to terminate run (#3642)
1 parent 189959e commit fa6637d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed
 

‎packages/vitest/src/node/cli-api.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,8 @@ export async function startVitest(
8787
return ctx
8888
}
8989

90-
if (process.stdin.isTTY && ctx.config.watch)
90+
if (process.stdin.isTTY)
9191
registerConsoleShortcuts(ctx)
92-
else
93-
process.on('SIGINT', () => ctx.cancelCurrentRun('keyboard-input'))
9492

9593
ctx.onServerRestart((reason) => {
9694
ctx.report('onServerRestart', reason)

‎packages/vitest/src/node/stdin.ts

+8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export function registerConsoleShortcuts(ctx: Vitest) {
3232
// If cancelling takes long and key is pressed multiple times, exit forcefully.
3333
if (str === '\x03' || str === '\x1B' || (key && key.ctrl && key.name === 'c')) {
3434
if (!ctx.isCancelling) {
35+
ctx.logger.logUpdate.clear()
36+
ctx.logger.log(c.red('Cancelling test run. Press CTRL+c again to exit forcefully.\n'))
37+
process.exitCode = 130
38+
3539
await ctx.cancelCurrentRun('keyboard-input')
3640
await ctx.runningPromise
3741
}
@@ -45,6 +49,10 @@ export function registerConsoleShortcuts(ctx: Vitest) {
4549
return
4650
}
4751

52+
// Other keys are for watch mode only
53+
if (!ctx.config.watch)
54+
return
55+
4856
const name = key?.name
4957

5058
if (ctx.runningPromise) {

0 commit comments

Comments
 (0)
Please sign in to comment.