From 798be414c472dd17427bb8c91efc061aa107061d Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Sat, 23 Nov 2024 14:20:57 +0900 Subject: [PATCH] fix: persist cli file filters --- packages/vitest/src/node/core.ts | 11 ++++++----- packages/vitest/src/node/reporters/base.ts | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/vitest/src/node/core.ts b/packages/vitest/src/node/core.ts index 4d54e6b763df..28448a2ba8e6 100644 --- a/packages/vitest/src/node/core.ts +++ b/packages/vitest/src/node/core.ts @@ -65,7 +65,7 @@ export class Vitest { invalidates: Set = new Set() changedTests: Set = new Set() watchedTests: Set = new Set() - filenamePattern?: string + filenamePattern?: string[] runningPromise?: Promise closingPromise?: Promise isCancelling = false @@ -414,6 +414,7 @@ export class Vitest { await this.report('onInit', this) } + this.filenamePattern = filters && filters?.length > 0 ? filters : undefined const files = await this.filterTestsBySource( await this.globTestFiles(filters), ) @@ -710,7 +711,7 @@ export class Vitest { } if (this.filenamePattern) { - const filteredFiles = await this.globTestFiles([this.filenamePattern]) + const filteredFiles = await this.globTestFiles(this.filenamePattern) files = files.filter(file => filteredFiles.some(f => f[1] === file)) } @@ -774,9 +775,9 @@ export class Vitest { } async changeFilenamePattern(pattern: string, files: string[] = this.state.getFilepaths()) { - this.filenamePattern = pattern + this.filenamePattern = pattern ? [pattern] : [] - const trigger = this.filenamePattern ? 'change filename pattern' : 'reset filename pattern' + const trigger = this.filenamePattern.length ? 'change filename pattern' : 'reset filename pattern' await this.rerunFiles(files, trigger, pattern === '') } @@ -844,7 +845,7 @@ export class Vitest { let files = Array.from(this.changedTests) if (this.filenamePattern) { - const filteredFiles = await this.globTestFiles([this.filenamePattern]) + const filteredFiles = await this.globTestFiles(this.filenamePattern) files = files.filter(file => filteredFiles.some(f => f[1] === file)) // A file that does not match the current filename pattern was changed diff --git a/packages/vitest/src/node/reporters/base.ts b/packages/vitest/src/node/reporters/base.ts index 6895adafa176..0c9d52a4b62b 100644 --- a/packages/vitest/src/node/reporters/base.ts +++ b/packages/vitest/src/node/reporters/base.ts @@ -209,7 +209,7 @@ export abstract class BaseReporter implements Reporter { } if (this.ctx.filenamePattern) { - this.log(BADGE_PADDING + c.dim(' Filename pattern: ') + c.blue(this.ctx.filenamePattern)) + this.log(BADGE_PADDING + c.dim(' Filename pattern: ') + c.blue(this.ctx.filenamePattern.join(', '))) } if (this.ctx.configOverride.testNamePattern) {