Skip to content

Commit 60a299b

Browse files
committed
fix: testNamePattern adds leading space
1 parent f68453f commit 60a299b

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

packages/runner/src/utils/collect.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ export function interpretTaskModes(
5757
}
5858

5959
function getTaskFullName(task: TaskBase): string {
60-
return `${task.suite ? `${getTaskFullName(task.suite)} ` : ''}${task.name}`
60+
const suiteName = task.suite ? getTaskFullName(task.suite) : null
61+
62+
return `${suiteName ? `${suiteName} ` : ''}${task.name}`
6163
}
6264

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

test/core/test/test-name-pattern.test.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
import { assert, describe, it } from 'vitest'
1+
import { afterAll, assert, describe, it } from 'vitest'
2+
3+
let testCount = 0
4+
5+
afterAll(() => {
6+
if (testCount !== 4) {
7+
assert.fail(`Expected to run 4 tests, instead ${testCount}`)
8+
}
9+
})
210

311
it('does include root test', () => {
412
assert.equal(Math.sqrt(4), 2)
13+
testCount++
514
})
615

716
it('does not include test that is root and unmatched', () => {
@@ -11,6 +20,7 @@ it('does not include test that is root and unmatched', () => {
1120
describe('testNamePattern', () => {
1221
it('does include test in describe', () => {
1322
assert.equal(Math.sqrt(4), 2)
23+
testCount++
1424
})
1525

1626
it('does not include test that is in describe and unmatched', () => {
@@ -20,10 +30,16 @@ describe('testNamePattern', () => {
2030
describe('nested describe', () => {
2131
it('does include nested test', () => {
2232
assert.equal(Math.sqrt(4), 2)
33+
testCount++
2334
})
2435

2536
it('does not include test that is nested and unmatched', () => {
2637
assert.fail('unmatched test was included')
2738
})
2839
})
2940
})
41+
42+
it('Match test name from the start', () => {
43+
assert.equal(Math.sqrt(4), 2)
44+
testCount++
45+
})

test/core/vite.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default defineConfig({
6363
setupFiles: [
6464
'./test/setup.ts',
6565
],
66-
testNamePattern: '^((?!does not include test that).)*$',
66+
testNamePattern: '(does include)|(^Match test name from the start)',
6767
coverage: {
6868
provider: 'istanbul',
6969
reporter: ['text', 'html'],

0 commit comments

Comments
 (0)