@@ -51,11 +51,17 @@ describe('Discovery', () => {
5151 return [ 201 , { data : { id : '4567' } } ] ;
5252 } ) ;
5353
54+ const dynamicImageRoutes = { } ;
55+ for ( let i = 0 ; i < 800 ; i ++ ) {
56+ dynamicImageRoutes [ `/dynamic/image-${ i } .png` ] = ( ) => [ 200 , 'image/png' , pixel ] ;
57+ }
58+
5459 server = await createTestServer ( {
5560 '/' : ( ) => [ 200 , 'text/html' , testDOM ] ,
5661 '/style.css' : ( ) => [ 200 , 'text/css' , testCSS ] ,
5762 '/img.gif' : ( ) => [ 200 , 'image/gif' , pixel ] ,
58- '/font.woff' : ( ) => [ 200 , 'font/woff' , '<font>' ]
63+ '/font.woff' : ( ) => [ 200 , 'font/woff' , '<font>' ] ,
64+ ...dynamicImageRoutes
5965 } ) ;
6066
6167 percy = await Percy . start ( {
@@ -1377,6 +1383,63 @@ describe('Discovery', () => {
13771383 } ) ;
13781384 } ) ;
13791385
1386+ describe ( 'Discovery with resource limit flag' , ( ) => {
1387+ const testDOM1 = dedent `
1388+ <html>
1389+ <head>
1390+ <link href="style.css" rel="stylesheet"/>
1391+ </head>
1392+ <body>
1393+ <p>Hello Percy!</p>
1394+ <img src="img.gif" decoding="async"/>
1395+ ${ Array . from ( { length : 800 } , ( _ , i ) =>
1396+ `<img src="/dynamic/image-${ i } .png" />`
1397+ ) . join ( '\n' ) }
1398+ </body>
1399+ </html>
1400+ ` ;
1401+ it ( 'limits resources when the flags are set' , async ( ) => {
1402+ percy . loglevel ( 'debug' ) ;
1403+ process . env . LIMIT_SNAPSHOT_RESOURCES = true ;
1404+ process . env . MAX_SNAPSHOT_RESOURCES = 1 ;
1405+ await percy . snapshot ( {
1406+ name : 'test snapshot' ,
1407+ url : 'http://localhost:8000' ,
1408+ domSnapshot : testDOM1
1409+ } ) ;
1410+
1411+ await percy . idle ( ) ;
1412+ expect ( captured [ 0 ] . length ) . toBeLessThanOrEqual ( 2 ) ; // 1 root + 1 non root
1413+ expect ( logger . stderr ) . toContain ( jasmine . stringMatching ( / r e s o u r c e l i m i t r e a c h e d / ) ) ;
1414+ } ) ;
1415+
1416+ it ( 'does not limit resources when the limit flag is not set' , async ( ) => {
1417+ delete process . env . LIMIT_SNAPSHOT_RESOURCES ;
1418+ await percy . snapshot ( {
1419+ name : 'test snapshot' ,
1420+ url : 'http://localhost:8000' ,
1421+ domSnapshot : testDOM1
1422+ } ) ;
1423+ await percy . idle ( ) ;
1424+ expect ( captured [ 0 ] . length ) . toBeGreaterThanOrEqual ( 1 ) ;
1425+ expect ( logger . stderr ) . not . toContain ( jasmine . stringMatching ( / r e s o u r c e l i m i t r e a c h e d / ) ) ;
1426+ delete process . env . MAX_SNAPSHOT_RESOURCES ;
1427+ } ) ;
1428+
1429+ it ( 'limit resources when flag is set but for default limit' , async ( ) => {
1430+ percy . loglevel ( 'debug' ) ;
1431+ process . env . LIMIT_SNAPSHOT_RESOURCES = true ;
1432+ await percy . snapshot ( {
1433+ name : 'test snapshot' ,
1434+ url : 'http://localhost:8000' ,
1435+ domSnapshot : testDOM1
1436+ } ) ;
1437+ await percy . idle ( ) ;
1438+ expect ( captured [ 0 ] . length ) . toBeLessThanOrEqual ( 750 ) ;
1439+ expect ( logger . stderr ) . toContain ( jasmine . stringMatching ( / r e s o u r c e l i m i t r e a c h e d / ) ) ;
1440+ } ) ;
1441+ } ) ;
1442+
13801443 describe ( 'discovery retry' , ( ) => {
13811444 let Page ;
13821445 let fastCount ;
0 commit comments