Skip to content

Commit d46a747

Browse files
authored
fix: treat test.describe as a suite during static collection (#11128)
1 parent 584cf30 commit d46a747

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎packages/vitest/src/node/ast-collect.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ function astParseFile(filepath: string, code: string) {
290290
start,
291291
end,
292292
name: message,
293-
type: isTestFunctionName(name) ? 'test' : 'suite',
293+
type: properties.includes('describe') || properties.includes('suite') || !isTestFunctionName(name) ? 'suite' : 'test',
294294
mode,
295295
task: null as any,
296296
dynamic: isDynamicEach,

‎test/e2e/test/static-collect.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,30 @@ test('correctly collects a simple test', async () => {
4242
`)
4343
})
4444

45+
test('collects test.describe as a suite', async () => {
46+
const testModule = await collectTests(`
47+
import { test } from 'vitest'
48+
49+
test.describe('scoped suite', () => {
50+
test('nested test', () => {})
51+
})
52+
`)
53+
expect(testModule).toMatchInlineSnapshot(`
54+
{
55+
"scoped suite": {
56+
"nested test": {
57+
"errors": [],
58+
"fullName": "scoped suite > nested test",
59+
"id": "1709388417_0_0",
60+
"location": "5:7",
61+
"mode": "run",
62+
"state": "pending",
63+
},
64+
},
65+
}
66+
`)
67+
})
68+
4569
test('ignores lowered "using" helper calls like it[1].call(it[2])', async () => {
4670
// parsers can inject this helper when lowering `using` declarations
4771
const testModule = await collectTests(`

0 commit comments

Comments
 (0)