Skip to content

Commit 98f76ea

Browse files
authoredNov 12, 2024··
fix: don't rerun on Esc or Ctrl-C during watch filter (#6895)
1 parent 07c19b8 commit 98f76ea

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed
 

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

+9
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ export function registerConsoleShortcuts(
149149
})
150150

151151
on()
152+
153+
if (typeof filter === 'undefined') {
154+
return
155+
}
156+
152157
const files = ctx.state.getFilepaths()
153158
// if running in standalone mode, Vitest instance doesn't know about any test file
154159
const cliFiles
@@ -193,6 +198,10 @@ export function registerConsoleShortcuts(
193198

194199
on()
195200

201+
if (typeof filter === 'undefined') {
202+
return
203+
}
204+
196205
latestFilename = filter?.trim() || ''
197206
const lastResults = watchFilter.getLastResults()
198207

‎packages/vitest/src/node/watch-filter.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ export class WatchFilter {
7474
break
7575
case key?.ctrl && key?.name === 'c':
7676
case key?.name === 'escape':
77-
this.cancel()
77+
this.write(`${ESC}1G${ESC}0J`) // clean content
7878
onSubmit(undefined)
79-
break
79+
return
8080
case key?.name === 'enter':
8181
case key?.name === 'return':
8282
onSubmit(
@@ -224,10 +224,6 @@ export class WatchFilter {
224224
this.write(`${ESC}${cursortPos}G`)
225225
}
226226

227-
private cancel() {
228-
this.write(`${ESC}J`) // erase down
229-
}
230-
231227
private write(data: string) {
232228
// @ts-expect-error -- write() method has different signature on the union type
233229
this.stdout.write(data)

0 commit comments

Comments
 (0)
Please sign in to comment.