From a47d52e23bfbec5c36fc0e70f809f5e09a117822 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Thu, 7 Sep 2023 16:50:18 +0800 Subject: [PATCH 1/2] fix(runner): incorrect test name pattern matching (#4071) (cherry picked from commit b5bf32907fae8b8b4508689a32205f94056a721e) --- packages/runner/src/utils/collect.ts | 3 ++- test/filters/test/testname-pattern.test.ts | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/runner/src/utils/collect.ts b/packages/runner/src/utils/collect.ts index b163bae7f716..9eeee4267833 100644 --- a/packages/runner/src/utils/collect.ts +++ b/packages/runner/src/utils/collect.ts @@ -46,7 +46,8 @@ export function interpretTaskModes(suite: Suite, namePattern?: string | RegExp, } function getTaskFullName(task: TaskBase): string { - return `${task.suite ? `${getTaskFullName(task.suite)} ` : ''}${task.name}` + const fullName = task.suite ? getTaskFullName(task.suite) : null + return fullName ? `${fullName} ${task.name}` : task.name } export function someTasksAreOnly(suite: Suite): boolean { diff --git a/test/filters/test/testname-pattern.test.ts b/test/filters/test/testname-pattern.test.ts index 6a134c6c1615..40fd9cadc4bf 100644 --- a/test/filters/test/testname-pattern.test.ts +++ b/test/filters/test/testname-pattern.test.ts @@ -30,3 +30,14 @@ test('match by pattern that also matches current working directory', async () => expect(stdout).toMatch('Test Files 1 passed (1)') expect(stdout).not.toMatch('test/example.test.ts') }) + +test('match by test name pattern with ^', async () => { + const { stdout } = await runVitest({ + root: './fixtures', + testNamePattern: '^this', + }, ['filters']) + + expect(stdout).toMatch('✓ test/filters.test.ts > this will pass') + expect(stdout).toMatch('Test Files 1 passed (1)') + expect(stdout).not.toMatch('test/example.test.ts') +}) From c93f74b27363ee573d3d5c7c026b2d453b3a486b Mon Sep 17 00:00:00 2001 From: Sergey Simonchik Date: Tue, 12 Sep 2023 15:55:44 +0200 Subject: [PATCH 2/2] fix(runner): another way to allow leading space in `testNamePattern` (#4103) --- packages/runner/src/utils/collect.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/runner/src/utils/collect.ts b/packages/runner/src/utils/collect.ts index 9eeee4267833..2842f4eb9a6b 100644 --- a/packages/runner/src/utils/collect.ts +++ b/packages/runner/src/utils/collect.ts @@ -27,8 +27,14 @@ export function interpretTaskModes(suite: Suite, namePattern?: string | RegExp, } } if (t.type === 'test') { - if (namePattern && !getTaskFullName(t).match(namePattern)) - t.mode = 'skip' + if (namePattern) { + const taskFullName = getTaskFullName(t) + // Match also the task full name with a leading space to be backward-compatible with tools like + // IntelliJ/WebStorm. Previous Vitest versions (<= 0.34.3) had the task full name starting + // with a space, and the tools passed `testNamePattern` matching it. + if (!(taskFullName.match(namePattern) || ` ${taskFullName}`.match(namePattern))) + t.mode = 'skip' + } } else if (t.type === 'suite') { if (t.mode === 'skip')