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

feat(watch): press r should rerun current pattern tests #3305

Merged
merged 9 commits into from May 6, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/vitest/src/node/stdin.ts
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
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')
})
sheremet-va marked this conversation as resolved.
Show resolved Hide resolved

test('filter by filename', async () => {
const vitest = await startWatchMode()

Expand Down