File tree 2 files changed +10
-2
lines changed
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(
79
79
80
80
if ( process . stdin . isTTY && ctx . config . watch )
81
81
registerConsoleShortcuts ( ctx )
82
+ else
83
+ process . on ( 'SIGINT' , ( ) => ctx . cancelCurrentRun ( 'keyboard-input' ) )
82
84
83
85
ctx . onServerRestart ( ( reason ) => {
84
86
ctx . report ( 'onServerRestart' , reason )
Original file line number Diff line number Diff line change @@ -28,9 +28,15 @@ export function registerConsoleShortcuts(ctx: Vitest) {
28
28
let latestFilename = ''
29
29
30
30
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
+ }
33
38
return ctx . exit ( true )
39
+ }
34
40
35
41
// window not support suspend
36
42
if ( ! isWindows && key && key . ctrl && key . name === 'z' ) {
You can’t perform that action at this time.
0 commit comments