11import type { AsyncExpectationResult , MatcherState } from '@vitest/expect'
2+ import type { TestAnnotation } from 'vitest'
23import type { ScreenshotMatcherOptions } from '../../../../context'
34import type { ScreenshotMatcherArguments , ScreenshotMatcherOutput } from '../../../shared/screenshotMatcher/types'
45import type { Locator } from '../locators'
@@ -69,21 +70,50 @@ export default async function toMatchScreenshot(
6970 if ( result . pass === false && 'context' in currentTest ) {
7071 const { annotate } = currentTest . context
7172
72- const annotations : ReturnType < typeof annotate > [ ] = [ ]
73+ const attachments : TestAnnotation [ 'attachments' ] = [ ]
7374
7475 if ( result . reference ) {
75- annotations . push ( annotate ( 'Reference screenshot' , { path : result . reference } ) )
76+ attachments . push ( {
77+ name : 'reference' ,
78+ path : result . reference . path ,
79+ metadata : {
80+ width : result . reference . metadata . width ,
81+ height : result . reference . metadata . height ,
82+ } ,
83+ } )
7684 }
7785
7886 if ( result . actual ) {
79- annotations . push ( annotate ( 'Actual screenshot' , { path : result . actual } ) )
87+ attachments . push ( {
88+ name : 'actual' ,
89+ path : result . actual . path ,
90+ metadata : {
91+ width : result . actual . metadata . width ,
92+ height : result . actual . metadata . height ,
93+ } ,
94+ } )
8095 }
8196
8297 if ( result . diff ) {
83- annotations . push ( annotate ( 'Diff' , { path : result . diff } ) )
98+ attachments . push ( {
99+ name : 'diff' ,
100+ path : result . diff ,
101+ } )
84102 }
85103
86- await Promise . all ( annotations )
104+ if ( attachments . length > 0 ) {
105+ await annotate ( {
106+ type : 'assertion-artifact' ,
107+ title : 'Visual Regression' ,
108+ message : result . message ,
109+ attachments,
110+ metadata : {
111+ 'internal:toMatchScreenshot' : {
112+ kind : 'visual-regression' ,
113+ } ,
114+ } ,
115+ } )
116+ }
87117 }
88118
89119 return {
@@ -96,14 +126,15 @@ export default async function toMatchScreenshot(
96126 '' ,
97127 result . message ,
98128 result . reference
99- ? `\nReference screenshot:\n ${ this . utils . EXPECTED_COLOR ( result . reference ) } `
129+ ? `\nReference screenshot:\n ${ this . utils . EXPECTED_COLOR ( result . reference . path ) } `
100130 : null ,
101131 result . actual
102- ? `\nActual screenshot:\n ${ this . utils . RECEIVED_COLOR ( result . actual ) } `
132+ ? `\nActual screenshot:\n ${ this . utils . RECEIVED_COLOR ( result . actual . path ) } `
103133 : null ,
104134 result . diff
105135 ? this . utils . DIM_COLOR ( `\nDiff image:\n ${ result . diff } ` )
106136 : null ,
137+ '' ,
107138 ]
108139 . filter ( element => element !== null )
109140 . join ( '\n' ) ,
0 commit comments