From 69d27117d85990536f4dec5a08f3d5bdb48578c9 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Sat, 6 May 2023 19:54:01 +0800 Subject: [PATCH] feat(watch): press `r` should rerun current pattern tests (#3305) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ari Perkkiƶ --- packages/vitest/src/node/stdin.ts | 10 +++++++--- test/watch/test/stdin.test.ts | 9 +++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/vitest/src/node/stdin.ts b/packages/vitest/src/node/stdin.ts index 1f81ded5637..20bbd7ab3ee 100644 --- a/packages/vitest/src/node/stdin.ts +++ b/packages/vitest/src/node/stdin.ts @@ -5,20 +5,21 @@ import { isWindows, stdout } from '../utils' import type { Vitest } from './core' const keys = [ - ['a', 'rerun all tests'], + [['a', 'return'], 'rerun all tests'], + ['r', 'rerun current pattern tests'], ['f', 'rerun only failed tests'], ['u', 'update snapshot'], ['p', 'filter by a filename'], ['t', 'filter by a test name regex pattern'], ['q', 'quit'], ] -const cancelKeys = ['space', 'c', ...keys.map(key => key[0])] +const cancelKeys = ['space', 'c', ...keys.map(key => key[0]).flat()] export function printShortcutsHelp() { stdout().write( ` ${c.bold(' Watch Usage')} -${keys.map(i => c.dim(' press ') + c.reset(c.bold(i[0])) + c.dim(` to ${i[1]}`)).join('\n')} +${keys.map(i => c.dim(' press ') + c.reset([i[0]].flat().map(c.bold).join(', ')) + c.dim(` to ${i[1]}`)).join('\n')} `, ) } @@ -63,6 +64,9 @@ export function registerConsoleShortcuts(ctx: Vitest) { // rerun all tests if (name === 'a' || name === 'return') return ctx.changeNamePattern('') + // rerun current pattern tests + if (name === 'r') + return ctx.rerunFiles() // rerun only failed tests if (name === 'f') return ctx.rerunFailed() diff --git a/test/watch/test/stdin.test.ts b/test/watch/test/stdin.test.ts index fd4d13a2af0..958c442e86a 100644 --- a/test/watch/test/stdin.test.ts +++ b/test/watch/test/stdin.test.ts @@ -17,6 +17,15 @@ test('quit watch mode', async () => { await vitest.isDone }) +test('rerun current pattern tests', async () => { + const vitest = await startWatchMode('-t', 'sum') + + vitest.write('r') + + await vitest.waitForOutput('Test name pattern: /sum/') + await vitest.waitForOutput('1 passed') +}) + test('filter by filename', async () => { const vitest = await startWatchMode()