From 6c61ab33536a32930b0a6a2f05ed260a4eb1198b Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Mon, 16 Dec 2024 18:32:35 +0100 Subject: [PATCH] anchor by attachment index --- packages/html-reporter/src/links.tsx | 5 ++-- packages/html-reporter/src/testFileView.tsx | 2 +- packages/html-reporter/src/testResultView.tsx | 27 +++++++++---------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/html-reporter/src/links.tsx b/packages/html-reporter/src/links.tsx index a6ea1e6695..ba9665571a 100644 --- a/packages/html-reporter/src/links.tsx +++ b/packages/html-reporter/src/links.tsx @@ -68,11 +68,12 @@ export const ProjectLink: React.FunctionComponent<{ export const AttachmentLink: React.FunctionComponent<{ attachment: TestAttachment, + result: TestResult, href?: string, linkName?: string, openInNewTab?: boolean, -}> = ({ attachment, href, linkName, openInNewTab }) => { - const isAnchored = useIsAnchored('attachment-' + attachment.name); +}> = ({ attachment, result, href, linkName, openInNewTab }) => { + const isAnchored = useIsAnchored('attachment-' + result.attachments.indexOf(attachment)); return {attachment.contentType === kMissingContentType ? icons.warning() : icons.attachment()} {attachment.path && {linkName || attachment.name}} diff --git a/packages/html-reporter/src/testFileView.tsx b/packages/html-reporter/src/testFileView.tsx index f8fad1d646..00ea004136 100644 --- a/packages/html-reporter/src/testFileView.tsx +++ b/packages/html-reporter/src/testFileView.tsx @@ -75,7 +75,7 @@ function imageDiffBadge(test: TestCaseSummary): JSX.Element | undefined { for (const result of test.results) { for (const attachment of result.attachments) { if (attachment.contentType.startsWith('image/') && !!attachment.name.match(/-(expected|actual|diff)/)) - return {image()}; + return {image()}; } } } diff --git a/packages/html-reporter/src/testResultView.tsx b/packages/html-reporter/src/testResultView.tsx index 410677cb02..9dcdf29092 100644 --- a/packages/html-reporter/src/testResultView.tsx +++ b/packages/html-reporter/src/testResultView.tsx @@ -32,7 +32,7 @@ interface ImageDiffWithAnchors extends ImageDiff { anchors: string[]; } -function groupImageDiffs(screenshots: Set): ImageDiffWithAnchors[] { +function groupImageDiffs(screenshots: Set, result: TestResult): ImageDiffWithAnchors[] { const snapshotNameToImageDiff = new Map(); for (const attachment of screenshots) { const match = attachment.name.match(/^(.*)-(expected|actual|diff|previous)(\.[^.]+)?$/); @@ -45,7 +45,7 @@ function groupImageDiffs(screenshots: Set): ImageDiffWithAnchors imageDiff = { name: snapshotName, anchors: [`attachment-${name}`] }; snapshotNameToImageDiff.set(snapshotName, imageDiff); } - imageDiff.anchors.push(`attachment-${attachment.name}`); + imageDiff.anchors.push(`attachment-${result.attachments.indexOf(attachment)}`); if (category === 'actual') imageDiff.actual = { attachment }; if (category === 'expected') @@ -72,15 +72,15 @@ export const TestResultView: React.FC<{ result: TestResult, }> = ({ test, result }) => { const { screenshots, videos, traces, otherAttachments, diffs, errors, otherAttachmentAnchors, screenshotAnchors } = React.useMemo(() => { - const attachments = result?.attachments || []; + const attachments = result.attachments; const screenshots = new Set(attachments.filter(a => a.contentType.startsWith('image/'))); - const screenshotAnchors = [...screenshots].map(a => `attachment-${a.name}`); + const screenshotAnchors = [...screenshots].map(a => `attachment-${attachments.indexOf(a)}`); const videos = attachments.filter(a => a.contentType.startsWith('video/')); const traces = attachments.filter(a => a.name === 'trace'); const otherAttachments = new Set(attachments); [...screenshots, ...videos, ...traces].forEach(a => otherAttachments.delete(a)); - const otherAttachmentAnchors = [...otherAttachments].map(a => `attachment-${a.name}`); - const diffs = groupImageDiffs(screenshots); + const otherAttachmentAnchors = [...otherAttachments].map(a => `attachment-${attachments.indexOf(a)}`); + const diffs = groupImageDiffs(screenshots, result); const errors = classifyErrors(result.errors, diffs); return { screenshots: [...screenshots], videos, traces, otherAttachments, diffs, errors, otherAttachmentAnchors, screenshotAnchors }; }, [result]); @@ -107,11 +107,11 @@ export const TestResultView: React.FC<{ {!!screenshots.length && {screenshots.map((a, i) => { - return + return - + ; })} } @@ -121,7 +121,7 @@ export const TestResultView: React.FC<{ - {traces.map((a, i) => )} + {traces.map((a, i) => )} } } @@ -130,14 +130,14 @@ export const TestResultView: React.FC<{ - + )} } {!!otherAttachments.size && {[...otherAttachments].map((a, i) => - - + + )} } @@ -174,10 +174,9 @@ const StepTreeItem: React.FC<{ step: TestStep; depth: number, }> = ({ test, step, result, depth }) => { - const attachmentName = step.title.match(/^attach "(.*)"$/)?.[1]; return {msToString(step.duration)} - {attachmentName && { evt.stopPropagation(); }}>{icons.attachment()}} + {step.attachments.length > 0 && { evt.stopPropagation(); }}>{icons.attachment()}} {statusIcon(step.error || step.duration === -1 ? 'failed' : 'passed')} {step.title} {step.count > 1 && <> ✕ {step.count}}