Skip to content

Commit b5bf329

Browse files
authored
fix(runner): incorrect test name pattern matching (#4071)
1 parent c54056a commit b5bf329

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/runner/src/utils/collect.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ export function interpretTaskModes(suite: Suite, namePattern?: string | RegExp,
4646
}
4747

4848
function getTaskFullName(task: TaskBase): string {
49-
return `${task.suite ? `${getTaskFullName(task.suite)} ` : ''}${task.name}`
49+
const fullName = task.suite ? getTaskFullName(task.suite) : null
50+
return fullName ? `${fullName} ${task.name}` : task.name
5051
}
5152

5253
export function someTasksAreOnly(suite: Suite): boolean {

test/filters/test/testname-pattern.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,14 @@ test('match by pattern that also matches current working directory', async () =>
3030
expect(stdout).toMatch('Test Files 1 passed (1)')
3131
expect(stdout).not.toMatch('test/example.test.ts')
3232
})
33+
34+
test('match by test name pattern with ^', async () => {
35+
const { stdout } = await runVitest({
36+
root: './fixtures',
37+
testNamePattern: '^this',
38+
}, ['filters'])
39+
40+
expect(stdout).toMatch('✓ test/filters.test.ts > this will pass')
41+
expect(stdout).toMatch('Test Files 1 passed (1)')
42+
expect(stdout).not.toMatch('test/example.test.ts')
43+
})

0 commit comments

Comments
 (0)