From 72942b16e619ffb25bc449ecf3d109a10dd1c542 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa <4232207+hi-ogawa@users.noreply.github.com> Date: Wed, 21 Oct 2026 18:22:03 +0900 Subject: [PATCH] refactor: require attempt for failure screenshot lookup Co-Authored-By: Claude Opus 5.5 --- packages/vitest/src/node/reporters/base.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/vitest/src/node/reporters/base.ts b/packages/vitest/src/node/reporters/base.ts index 56d3b3932..199cef44d 100644 --- a/packages/vitest/src/node/reporters/base.ts +++ b/packages/vitest/src/node/reporters/base.ts @@ -1506,7 +1506,9 @@ export abstract class BaseReporter implements Reporter { attemptsByTask.set(task, (attemptsByTask.get(task) ?? new Set()).add(attempt)) } const screenshotPaths = [...attemptsByTask].flatMap(([task, attempts]) => - [...attempts].flatMap((attempt) => getFailureScreenshotPaths(task, attempt)), + [...attempts].flatMap((attempt) => + attempt ? getFailureScreenshotPaths(task, attempt) : [], + ), ) for (const task of tasks) { const filepath = (task as File)?.filepath || '' @@ -1560,7 +1562,7 @@ function getErrorsWithAttempt(task: Task): { error: TestError; attempt?: TaskRes return attempts.flatMap((attempt) => (attempt.errors ?? []).map((error) => ({ error, attempt }))) } -function getFailureScreenshotPaths(task: Task, attempt?: TaskResultAttempt): string[] { +function getFailureScreenshotPaths(task: Task, attempt: TaskResultAttempt): string[] { if (task.type !== 'test') { return [] } @@ -1569,9 +1571,8 @@ function getFailureScreenshotPaths(task: Task, attempt?: TaskResultAttempt): str if ( artifact.type === 'internal:failureScreenshot' && artifact.attachments.length && - (!attempt || - (artifact.retryIndex === attempt.retryIndex && - artifact.repeatIndex === attempt.repeatIndex)) + artifact.retryIndex === attempt.retryIndex && + artifact.repeatIndex === attempt.repeatIndex ) { paths.push(artifact.attachments[0].originalPath) } -- 2.54.0