@@ -10,9 +10,9 @@ const dataTestId = 'colors-box'
1010const renderTestCase = ( colors : readonly [ string , string , string ] ) =>
1111 render ( `
1212 <div style="--size: ${ blockSize } px; display: flex; justify-content: center; height: var(--size); width: calc(var(--size) * ${ blocks } );" data-testid="${ dataTestId } ">
13- <div style="background-color: ${ colors [ 0 ] } ; width: var(--size);"></div>
14- <div style="background-color: ${ colors [ 1 ] } ; width: var(--size);"></div>
15- <div style="background-color: ${ colors [ 2 ] } ; width: var(--size);"></div>
13+ <div data-testid=" ${ dataTestId } -1" style="background-color: ${ colors [ 0 ] } ; width: var(--size);"></div>
14+ <div data-testid=" ${ dataTestId } -2" style="background-color: ${ colors [ 1 ] } ; width: var(--size);"></div>
15+ <div data-testid=" ${ dataTestId } -3" style="background-color: ${ colors [ 2 ] } ; width: var(--size);"></div>
1616 </div>
1717 ` )
1818
@@ -316,4 +316,58 @@ describe('.toMatchScreenshot', () => {
316316 await expect ( locator ) . toMatchScreenshot ( )
317317 } ,
318318 )
319+
320+ // `mask` is a Playwright-only screenshot feature
321+ test . runIf ( server . provider === 'playwright' ) (
322+ "works with masks" ,
323+ async ( { onTestFinished } ) => {
324+ const filename = globalThis . crypto . randomUUID ( )
325+ const path = join (
326+ '__screenshots__' ,
327+ 'toMatchScreenshot.test.ts' ,
328+ `${ filename } -${ server . browser } -${ server . platform } .png` ,
329+ )
330+
331+ onTestFinished ( async ( ) => {
332+ await server . commands . removeFile ( path )
333+ } )
334+
335+ renderTestCase ( [
336+ 'oklch(39.6% 0.141 25.723)' ,
337+ 'oklch(40.5% 0.101 131.063)' ,
338+ 'oklch(37.9% 0.146 265.522)' ,
339+ ] )
340+
341+ const locator = page . getByTestId ( dataTestId )
342+
343+ const maskColor = 'oklch(84.1% 0.238 128.85)'
344+ const mask = [ page . getByTestId ( `${ dataTestId } -3` ) ]
345+
346+ // Create reference with the third box masked
347+ await locator . screenshot ( {
348+ save : true ,
349+ path,
350+ maskColor,
351+ mask,
352+ } )
353+
354+ // Change the last box's color so we're sure `mask` works
355+ // The test would otherwise fail as the screenshots wouldn't match
356+ renderTestCase ( [
357+ 'oklch(39.6% 0.141 25.723)' ,
358+ 'oklch(40.5% 0.101 131.063)' ,
359+ 'oklch(39.6% 0.141 25.723)' ,
360+ ] )
361+
362+ await expect ( locator ) . toMatchScreenshot (
363+ filename ,
364+ {
365+ screenshotOptions : {
366+ maskColor,
367+ mask,
368+ } ,
369+ } ,
370+ )
371+ } ,
372+ )
319373} )
0 commit comments