From 98f76ea75fd03fdfffc24e9a7472612b1f82d5b3 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Tue, 12 Nov 2024 21:41:15 +0900 Subject: [PATCH] fix: don't rerun on Esc or Ctrl-C during watch filter (#6895) --- packages/vitest/src/node/stdin.ts | 9 +++++++++ packages/vitest/src/node/watch-filter.ts | 8 ++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/vitest/src/node/stdin.ts b/packages/vitest/src/node/stdin.ts index 40930f279e62..889439595e1e 100644 --- a/packages/vitest/src/node/stdin.ts +++ b/packages/vitest/src/node/stdin.ts @@ -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 @@ -193,6 +198,10 @@ export function registerConsoleShortcuts( on() + if (typeof filter === 'undefined') { + return + } + latestFilename = filter?.trim() || '' const lastResults = watchFilter.getLastResults() diff --git a/packages/vitest/src/node/watch-filter.ts b/packages/vitest/src/node/watch-filter.ts index 66b06e10c0f3..4fad0660ad24 100644 --- a/packages/vitest/src/node/watch-filter.ts +++ b/packages/vitest/src/node/watch-filter.ts @@ -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( @@ -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)