Skip to content

Commit 130f79b

Browse files
authored
fix: ignore computed member calls in static collection (#11085)
1 parent c10a129 commit 130f79b

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ function astParseFile(filepath: string, code: string) {
109109
return getName(callee.tag)
110110
}
111111
if (callee.type === 'MemberExpression') {
112+
// A computed access like `it[1].call(it[2])` is not a Vitest call.
113+
if (callee.computed) {
114+
return null
115+
}
112116
if (
113117
callee.object?.type === 'Identifier'
114118
&& isVitestFunctionName(callee.object.name)

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

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

45+
test('ignores lowered "using" helper calls like it[1].call(it[2])', async () => {
46+
// parsers can inject this helper when lowering `using` declarations
47+
const testModule = await collectTests(`
48+
import { describe, test } from 'vitest'
49+
50+
var __callDispose = (stack, error, hasError) => {
51+
var next = (it) => {
52+
while (it = stack.pop()) {
53+
var result = it[1] && it[1].call(it[2])
54+
}
55+
}
56+
return next()
57+
}
58+
59+
describe('disposable', () => {
60+
test('uses a resource', () => {
61+
var _stack = []
62+
__callDispose(_stack)
63+
})
64+
})
65+
`)
66+
expect(testModule).toMatchInlineSnapshot(`
67+
{
68+
"disposable": {
69+
"uses a resource": {
70+
"errors": [],
71+
"fullName": "disposable > uses a resource",
72+
"id": "1709388417_0_0",
73+
"location": "14:7",
74+
"mode": "run",
75+
"state": "pending",
76+
},
77+
},
78+
}
79+
`)
80+
})
81+
4582
test('collects tests starting with "test"', async () => {
4683
const testModule = await collectTests(`
4784
import { testSomething, testAnother } from './test-helpers'

0 commit comments

Comments
 (0)
Sponsor
SponsoredKunjungi sekarang
Promo