Skip to content

Commit

Permalink
fix(runner): incorrect test name pattern matching (#4071)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing authored Sep 7, 2023
1 parent c54056a commit b5bf329
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/runner/src/utils/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions test/filters/test/testname-pattern.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})

0 comments on commit b5bf329

Please sign in to comment.