Skip to content

Commit

Permalink
feat(watch): press r should rerun current pattern tests (#3305)
Browse files Browse the repository at this point in the history
Co-authored-by: Ari Perkkiö <ari.perkkio@gmail.com>
  • Loading branch information
Dunqing and AriPerkkio authored May 6, 2023
1 parent 77d071a commit 69d2711
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/vitest/src/node/stdin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')}
`,
)
}
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions test/watch/test/stdin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 69d2711

Please sign in to comment.