@@ -178,7 +178,7 @@ describe('basic', () => {
178178 await page . waitForTimeout ( 500 )
179179 // get content of #script-src
180180 const text = await page . $eval ( '#script-src' , el => el . textContent )
181- expect ( text ) . toMatchInlineSnapshot ( `"/_scripts/assets/6bEy8slcRmYcRT4E2QbQZ1CMyWw9PpHA7L87BtvSs2U .js"` )
181+ expect ( text ) . toMatchInlineSnapshot ( `"/_scripts/assets/PHzhM8DFXcXVSSJF110cyV3pjg9cp8oWv_f4Dk2ax1w .js"` )
182182 } )
183183 it ( 'partytown adds type attribute' , async ( ) => {
184184 const { page } = await createPage ( '/partytown' )
@@ -234,6 +234,60 @@ describe('youtube', () => {
234234 } )
235235} )
236236
237+ describe ( 'gravatar' , ( ) => {
238+ async function expectImageSnapshot ( buffer : Buffer , id : string ) {
239+ const { toMatchImageSnapshot } = await import ( 'jest-image-snapshot' )
240+ expect . extend ( { toMatchImageSnapshot } )
241+ ; ( expect ( buffer ) as any ) . toMatchImageSnapshot ( {
242+ customSnapshotIdentifier : id ,
243+ customSnapshotsDir : `${ import . meta. dirname } /__image_snapshots__` ,
244+ } )
245+ }
246+
247+ it ( 'proxy returns valid image for email lookup' , {
248+ timeout : 15000 ,
249+ } , async ( ) => {
250+ const response = await fetch ( url ( '/_scripts/proxy/gravatar?email=test@example.com&s=80&d=identicon&r=g' ) )
251+ expect ( response . status ) . toBe ( 200 )
252+ expect ( response . headers . get ( 'content-type' ) ) . toContain ( 'image/' )
253+ expect ( response . headers . get ( 'cache-control' ) ) . toContain ( 'public' )
254+
255+ const buffer = Buffer . from ( await response . arrayBuffer ( ) )
256+ expect ( buffer . length ) . toBeGreaterThan ( 100 )
257+ await expectImageSnapshot ( buffer , 'gravatar-email-proxy' )
258+ } )
259+
260+ it ( 'proxy returns valid image for hash lookup' , {
261+ timeout : 15000 ,
262+ } , async ( ) => {
263+ // SHA256 of "test@example.com"
264+ const hash = '973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b'
265+ const response = await fetch ( url ( `/_scripts/proxy/gravatar?hash=${ hash } &s=80&d=identicon&r=g` ) )
266+ expect ( response . status ) . toBe ( 200 )
267+ expect ( response . headers . get ( 'content-type' ) ) . toContain ( 'image/' )
268+
269+ const buffer = Buffer . from ( await response . arrayBuffer ( ) )
270+ expect ( buffer . length ) . toBeGreaterThan ( 100 )
271+ await expectImageSnapshot ( buffer , 'gravatar-hash-proxy' )
272+ } )
273+
274+ it ( 'email and hash proxy return identical images' , {
275+ timeout : 15000 ,
276+ } , async ( ) => {
277+ const hash = '973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b'
278+ const [ emailRes , hashRes ] = await Promise . all ( [
279+ fetch ( url ( '/_scripts/proxy/gravatar?email=test@example.com&s=80&d=identicon&r=g' ) ) ,
280+ fetch ( url ( `/_scripts/proxy/gravatar?hash=${ hash } &s=80&d=identicon&r=g` ) ) ,
281+ ] )
282+
283+ const emailBuffer = Buffer . from ( await emailRes . arrayBuffer ( ) )
284+ const hashBuffer = Buffer . from ( await hashRes . arrayBuffer ( ) )
285+
286+ // Same email hashed server-side should produce identical image to pre-computed hash
287+ expect ( emailBuffer . equals ( hashBuffer ) ) . toBe ( true )
288+ } )
289+ } )
290+
237291describe ( 'third-party-capital' , ( ) => {
238292 it ( 'expect GA to collect data' , {
239293 timeout : 10000 ,
0 commit comments