Skip to content

Commit c21865d

Browse files
hi-ogawaOpenCode (gpt-5.6-sol)
andauthored
fix: fix recordArtifact location with vi.defineHelper (#11047)
Co-authored-by: Hiroshi Ogawa <4232207+hi-ogawa@users.noreply.github.com> Co-authored-by: OpenCode (gpt-5.6-sol) <noreply@opencode.ai>
1 parent cd63e9e commit c21865d

2 files changed

Lines changed: 37 additions & 9 deletions

File tree

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ParsedStack } from '@vitest/utils'
2-
import { parseSingleStack } from '@vitest/utils/source-map'
2+
import { parseStacktrace } from '@vitest/utils/source-map'
33

44
export function findTestFileStackTrace(testFilePath: string, error: Error): ParsedStack | undefined {
55
let stack: string | undefined
@@ -14,12 +14,6 @@ export function findTestFileStackTrace(testFilePath: string, error: Error): Pars
1414
if (!stack) {
1515
return undefined
1616
}
17-
// first line is the error message
18-
const lines = stack.split('\n').slice(1)
19-
for (const line of lines) {
20-
const parsed = parseSingleStack(line)
21-
if (parsed && parsed.file === testFilePath) {
22-
return parsed
23-
}
24-
}
17+
return parseStacktrace(stack, { ignoreStackEntries: [] })
18+
.find(stack => stack.file === testFilePath)
2519
}

‎test/e2e/test/artifacts.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,40 @@ describe('API', () => {
265265
}, { globals: true })
266266
expect(stderr).toBe('')
267267
})
268+
269+
test('recordArtifact uses vi.defineHelper callsite', async () => {
270+
const artifacts: TestArtifact[] = []
271+
const { root, stderr } = await runInlineTests({
272+
'basic.test.ts': `
273+
import { recordArtifact, test, vi } from 'vitest'
274+
275+
const record = vi.defineHelper(async (task) => {
276+
await Promise.resolve()
277+
return recordArtifact(task, { type: 'helper' })
278+
})
279+
280+
test('records an artifact', async ({ task }) => {
281+
await record(task)
282+
})
283+
`,
284+
}, {
285+
reporters: [{
286+
onTestCaseResult(testCase) {
287+
artifacts.push(...testCase.artifacts())
288+
},
289+
}],
290+
})
291+
292+
expect(stderr).toBe('')
293+
expect(artifacts).toHaveLength(1)
294+
expect(artifacts[0]).toMatchObject({
295+
type: 'helper',
296+
location: {
297+
file: resolve(root, 'basic.test.ts'),
298+
line: 10,
299+
},
300+
})
301+
})
268302
})
269303

270304
// verify artifacts don't affect reporter output

0 commit comments

Comments
 (0)