Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: CTRL+C to terminate run #3642

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/vitest/src/node/cli-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions packages/vitest/src/node/stdin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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) {
Expand Down