File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,8 @@ export async function startVitest(
7979
8080 if ( process . stdin . isTTY && ctx . config . watch )
8181 registerConsoleShortcuts ( ctx )
82+ else
83+ process . on ( 'SIGINT' , ( ) => ctx . cancelCurrentRun ( 'keyboard-input' ) )
8284
8385 ctx . onServerRestart ( ( reason ) => {
8486 ctx . report ( 'onServerRestart' , reason )
Original file line number Diff line number Diff line change @@ -28,9 +28,15 @@ export function registerConsoleShortcuts(ctx: Vitest) {
2828 let latestFilename = ''
2929
3030 async function _keypressHandler ( str : string , key : any ) {
31- // ctrl-c or esc
32- if ( str === '\x03' || str === '\x1B' || ( key && key . ctrl && key . name === 'c' ) )
31+ // Cancel run and exit when ctrl-c or esc is pressed.
32+ // If cancelling takes long and key is pressed multiple times, exit forcefully.
33+ if ( str === '\x03' || str === '\x1B' || ( key && key . ctrl && key . name === 'c' ) ) {
34+ if ( ! ctx . isCancelling ) {
35+ await ctx . cancelCurrentRun ( 'keyboard-input' )
36+ await ctx . runningPromise
37+ }
3338 return ctx . exit ( true )
39+ }
3440
3541 // window not support suspend
3642 if ( ! isWindows && key && key . ctrl && key . name === 'z' ) {
You can’t perform that action at this time.
0 commit comments