Skip to content

Commit 69d2711

Browse files
DunqingAriPerkkio
andauthoredMay 6, 2023
feat(watch): press r should rerun current pattern tests (#3305)
Co-authored-by: Ari Perkkiö <ari.perkkio@gmail.com>
1 parent 77d071a commit 69d2711

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed
 

‎packages/vitest/src/node/stdin.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@ import { isWindows, stdout } from '../utils'
55
import type { Vitest } from './core'
66

77
const keys = [
8-
['a', 'rerun all tests'],
8+
[['a', 'return'], 'rerun all tests'],
9+
['r', 'rerun current pattern tests'],
910
['f', 'rerun only failed tests'],
1011
['u', 'update snapshot'],
1112
['p', 'filter by a filename'],
1213
['t', 'filter by a test name regex pattern'],
1314
['q', 'quit'],
1415
]
15-
const cancelKeys = ['space', 'c', ...keys.map(key => key[0])]
16+
const cancelKeys = ['space', 'c', ...keys.map(key => key[0]).flat()]
1617

1718
export function printShortcutsHelp() {
1819
stdout().write(
1920
`
2021
${c.bold(' Watch Usage')}
21-
${keys.map(i => c.dim(' press ') + c.reset(c.bold(i[0])) + c.dim(` to ${i[1]}`)).join('\n')}
22+
${keys.map(i => c.dim(' press ') + c.reset([i[0]].flat().map(c.bold).join(', ')) + c.dim(` to ${i[1]}`)).join('\n')}
2223
`,
2324
)
2425
}
@@ -63,6 +64,9 @@ export function registerConsoleShortcuts(ctx: Vitest) {
6364
// rerun all tests
6465
if (name === 'a' || name === 'return')
6566
return ctx.changeNamePattern('')
67+
// rerun current pattern tests
68+
if (name === 'r')
69+
return ctx.rerunFiles()
6670
// rerun only failed tests
6771
if (name === 'f')
6872
return ctx.rerunFailed()

‎test/watch/test/stdin.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ test('quit watch mode', async () => {
1717
await vitest.isDone
1818
})
1919

20+
test('rerun current pattern tests', async () => {
21+
const vitest = await startWatchMode('-t', 'sum')
22+
23+
vitest.write('r')
24+
25+
await vitest.waitForOutput('Test name pattern: /sum/')
26+
await vitest.waitForOutput('1 passed')
27+
})
28+
2029
test('filter by filename', async () => {
2130
const vitest = await startWatchMode()
2231

0 commit comments

Comments
 (0)
Please sign in to comment.