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: don't rerun on Esc or Ctrl-C during watch filter #6895

Merged
merged 2 commits into from
Nov 12, 2024
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
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