Skip to content

Commit

Permalink
fix: don't rerun on Esc or Ctrl-C during watch filter (#6895)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Nov 12, 2024
1 parent 07c19b8 commit 98f76ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 9 additions & 0 deletions packages/vitest/src/node/stdin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ export function registerConsoleShortcuts(
})

on()

if (typeof filter === 'undefined') {
return
}

const files = ctx.state.getFilepaths()
// if running in standalone mode, Vitest instance doesn't know about any test file
const cliFiles
Expand Down Expand Up @@ -193,6 +198,10 @@ export function registerConsoleShortcuts(

on()

if (typeof filter === 'undefined') {
return
}

latestFilename = filter?.trim() || ''
const lastResults = watchFilter.getLastResults()

Expand Down
8 changes: 2 additions & 6 deletions packages/vitest/src/node/watch-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ export class WatchFilter {
break
case key?.ctrl && key?.name === 'c':
case key?.name === 'escape':
this.cancel()
this.write(`${ESC}1G${ESC}0J`) // clean content
onSubmit(undefined)
break
return
case key?.name === 'enter':
case key?.name === 'return':
onSubmit(
Expand Down Expand Up @@ -224,10 +224,6 @@ export class WatchFilter {
this.write(`${ESC}${cursortPos}G`)
}

private cancel() {
this.write(`${ESC}J`) // erase down
}

private write(data: string) {
// @ts-expect-error -- write() method has different signature on the union type
this.stdout.write(data)
Expand Down

0 comments on commit 98f76ea

Please sign in to comment.