@@ -191,6 +191,23 @@ const checkNavigation = (name: string, run: () => Promise<void>) => check('navig
191191const checkComposer = ( name : string , run : ( ) => Promise < void > ) => check ( 'composer' , name , run )
192192const checkAccess = ( name : string , run : ( ) => Promise < void > ) => check ( 'access' , name , run )
193193
194+ /**
195+ * A screenshot taken once two consecutive captures match, so a pixel comparison between two
196+ * renderings of an element is not decided by a frame captured mid-paint.
197+ */
198+ async function settledScreenshot (
199+ target : Locator ,
200+ options : Parameters < Locator [ 'screenshot' ] > [ 0 ]
201+ ) : Promise < Buffer > {
202+ let previous = await target . screenshot ( options )
203+ for ( let capture = 0 ; capture < 10 ; capture ++ ) {
204+ const next = await target . screenshot ( options )
205+ if ( next . equals ( previous ) ) return next
206+ previous = next
207+ }
208+ throw new Error ( 'The element kept repainting across ten screenshots' )
209+ }
210+
194211async function screenshot ( name : string , target = panel ) {
195212 if ( ! target ) return
196213 for ( const frame of target . frames ( ) ) {
@@ -1163,8 +1180,8 @@ try {
11631180 . toBe ( true )
11641181 if ( width === 320 ) {
11651182 const chip = attachments ( ) . first ( )
1166- const visible = await chip . screenshot ( { animations : 'disabled' } )
1167- const withoutEdgeMask = await chip . screenshot ( {
1183+ const visible = await settledScreenshot ( chip , { animations : 'disabled' } )
1184+ const withoutEdgeMask = await settledScreenshot ( chip , {
11681185 animations : 'disabled' ,
11691186 style :
11701187 'div:has(> div > [aria-label="Page attached to next message"]) { mask-image: none !important; }' ,
0 commit comments