From 4908339ec21230d9cd61d63e5ee2bfa37e425a64 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Tue, 23 Apr 2024 10:41:40 +0200 Subject: [PATCH] fix: rerun _all_ tests when pressing "a" or "return" --- packages/vitest/src/node/core.ts | 4 ++++ packages/vitest/src/node/stdin.ts | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/vitest/src/node/core.ts b/packages/vitest/src/node/core.ts index 056334641b05..1a88fce65969 100644 --- a/packages/vitest/src/node/core.ts +++ b/packages/vitest/src/node/core.ts @@ -962,6 +962,10 @@ export class Vitest { ))) } + public async getTestFilepaths() { + return this.globTestFiles().then(files => files.map(([, file]) => file)) + } + public async globTestFiles(filters: string[] = []) { const files: WorkspaceSpec[] = [] await Promise.all(this.projects.map(async (project) => { diff --git a/packages/vitest/src/node/stdin.ts b/packages/vitest/src/node/stdin.ts index f5a5cc783e69..547f0068f811 100644 --- a/packages/vitest/src/node/stdin.ts +++ b/packages/vitest/src/node/stdin.ts @@ -72,8 +72,10 @@ export function registerConsoleShortcuts(ctx: Vitest) { if (name === 'u') return ctx.updateSnapshot() // rerun all tests - if (name === 'a' || name === 'return') - return ctx.changeNamePattern('') + if (name === 'a' || name === 'return') { + const files = await ctx.getTestFilepaths() + return ctx.changeNamePattern('', files, 'rerun all tests') + } // rerun current pattern tests if (name === 'r') return ctx.rerunFiles() @@ -115,7 +117,7 @@ export function registerConsoleShortcuts(ctx: Vitest) { const files = ctx.state.getFilepaths() // if running in standalone mode, Vitest instance doesn't know about any test file const cliFiles = ctx.config.standalone && !files.length - ? (await ctx.globTestFiles()).map(([_, file]) => file) + ? await ctx.getTestFilepaths() : undefined await ctx.changeNamePattern(filter?.trim() || '', cliFiles, 'change pattern')