@@ -8,21 +8,15 @@ import {
88 INTERNAL_REPORTS_DIRECTORY_PATH ,
99} from '../../constants/internal' ;
1010import { getOutputDirectoryName } from '../../context/outputDirectoryName' ;
11- import { getTestStaticOptions } from '../../context/testStaticOptions' ;
1211
1312import { getFullPackConfig } from '../config' ;
14- import { getPathToPack , getRunLabel } from '../environment' ;
1513import { E2edError } from '../error' ;
1614import { writeFile } from '../fs' ;
1715import { setReadonlyProperty } from '../setReadonlyProperty' ;
1816
19- import type {
20- FilePathFromRoot ,
21- ScreenshotMeta ,
22- Selector ,
23- ToMatchScreenshotOptions ,
24- Url ,
25- } from '../../types/internal' ;
17+ import { getScreenshotMeta } from './getScreenshotMeta' ;
18+
19+ import type { FilePathFromRoot , Selector , ToMatchScreenshotOptions , Url } from '../../types/internal' ;
2620
2721import type { Expect } from './Expect' ;
2822
@@ -70,12 +64,14 @@ export const toMatchScreenshot = async (
7064
7165 setReadonlyProperty ( context , 'additionalLogFields' , additionalLogFields ) ;
7266
67+ const meta = getScreenshotMeta ( { actualValue, description, expectedScreenshotId, options} ) ;
68+
7369 let expectedScreenshotFound = false ;
7470
7571 if ( expectedScreenshotId ) {
7672 additionalLogFields . expectedScreenshotUrl = getScreenshotUrlById ( expectedScreenshotId ) ;
7773
78- const expectedScreenshot = await readScreenshot ( expectedScreenshotId ) ;
74+ const expectedScreenshot = await readScreenshot ( expectedScreenshotId , meta ) ;
7975
8076 if ( expectedScreenshot !== undefined ) {
8177 expectedScreenshotFound = true ;
@@ -99,16 +95,6 @@ export const toMatchScreenshot = async (
9995 }
10096
10197 const { mask = [ ] , ...restOptions } = options ;
102- const meta : ScreenshotMeta = {
103- description,
104- isDiff : false ,
105- options,
106- pathToPack : getPathToPack ( ) ,
107- runLabel : getRunLabel ( ) ,
108- selector : actualValue . description ,
109- testStaticOptions : getTestStaticOptions ( ) ,
110- writeTimeInMs : Date . now ( ) ,
111- } ;
11298
11399 try {
114100 const playwrightLocator = actualValue . getPlaywrightLocator ( ) ;
@@ -131,7 +117,10 @@ export const toMatchScreenshot = async (
131117 additionalLogFields . actualScreenshotUrl = getScreenshotUrlById ( actualScreenshotId ) ;
132118
133119 const diffScreenshot = await readFile ( diffScreenshotPath ) ;
134- const diffScreenshotId = await writeScreenshot ( diffScreenshot , { ...meta , isDiff : true } ) ;
120+ const diffScreenshotId = await writeScreenshot ( diffScreenshot , {
121+ ...meta ,
122+ actual : actualScreenshotId ,
123+ } ) ;
135124
136125 additionalLogFields . diffScreenshotId = diffScreenshotId ;
137126 additionalLogFields . diffScreenshotUrl = getScreenshotUrlById ( diffScreenshotId ) ;
0 commit comments