@@ -51,6 +51,15 @@ describe('Discovery', () => {
5151 return [ 201 , { data : { id : '4567' } } ] ;
5252 } ) ;
5353
54+ // Mock domain config endpoint - return empty config by default
55+ api . reply ( '/projects/domain-config' , ( ) => [ 200 , {
56+ data : {
57+ type : 'projects' ,
58+ id : '123' ,
59+ attributes : { }
60+ }
61+ } ] ) ;
62+
5463 const dynamicImageRoutes = { } ;
5564 for ( let i = 0 ; i < 800 ; i ++ ) {
5665 dynamicImageRoutes [ `/dynamic/image-${ i } .png` ] = ( ) => [ 200 , 'image/png' , pixel ] ;
@@ -2896,6 +2905,9 @@ describe('Discovery', () => {
28962905 it ( 'loads domain config early from API before discovery starts' , async ( ) => {
28972906 await percy . stop ( ) ;
28982907
2908+ // Clear previous mocks and set up new one
2909+ api . replies [ '/projects/domain-config' ] = [ ] ;
2910+
28992911 // Mock API response for domain config endpoint
29002912 api . reply ( '/projects/domain-config' , ( ) => [ 200 , {
29012913 data : {
@@ -2904,7 +2916,6 @@ describe('Discovery', () => {
29042916 'domain-config' : {
29052917 'allowed-domains' : [ 'cdn.example.com' , 'images.example.com' ] ,
29062918 'blocked-domains' : [ 'evil.example.com' ] ,
2907- 'auto-allow-enabled' : true ,
29082919 'updated-at' : '2024-01-01T00:00:00Z' ,
29092920 'last-build-id' : '123'
29102921 }
@@ -2927,6 +2938,9 @@ describe('Discovery', () => {
29272938 it ( 'handles missing domain config gracefully during early load' , async ( ) => {
29282939 await percy . stop ( ) ;
29292940
2941+ // Clear previous mocks and set up empty config
2942+ api . replies [ '/projects/domain-config' ] = [ ] ;
2943+
29302944 // Mock API response with no domain config
29312945 api . reply ( '/projects/domain-config' , ( ) => [ 200 , {
29322946 data : {
@@ -2947,6 +2961,9 @@ describe('Discovery', () => {
29472961 it ( 'continues without domain config if API call fails during early load' , async ( ) => {
29482962 await percy . stop ( ) ;
29492963
2964+ // Clear previous mocks and set up error response
2965+ api . replies [ '/projects/domain-config' ] = [ ] ;
2966+
29502967 // Mock API to return error
29512968 api . reply ( '/projects/domain-config' , ( ) => [ 404 , 'Not Found' ] ) ;
29522969
@@ -3594,9 +3611,14 @@ describe('Discovery', () => {
35943611
35953612 describe ( 'waitForSelector/waitForTimeout at the time of discovery when Js is enabled =>' , ( ) => {
35963613 it ( 'calls waitForTimeout, waitForSelector and page.eval when their respective arguments are given' , async ( ) => {
3597- const page = await percy . browser . page ( { intercept : { getResource : ( ) => { } } } ) ;
3598- spyOn ( percy . browser , 'page' ) . and . returnValue ( page ) ;
3599- spyOn ( page , 'eval' ) . and . callThrough ( ) ;
3614+ let capturedPage ;
3615+ const originalPageMethod = percy . browser . page . bind ( percy . browser ) ;
3616+ spyOn ( percy . browser , 'page' ) . and . callFake ( async ( options ) => {
3617+ capturedPage = await originalPageMethod ( options ) ;
3618+ spyOn ( capturedPage , 'eval' ) . and . callThrough ( ) ;
3619+ return capturedPage ;
3620+ } ) ;
3621+
36003622 percy . loglevel ( 'debug' ) ;
36013623
36023624 await percy . snapshot ( {
@@ -3610,7 +3632,7 @@ describe('Discovery', () => {
36103632 } ) ;
36113633 await percy . idle ( ) ;
36123634
3613- expect ( page . eval ) . toHaveBeenCalledWith ( 'await waitForSelector("body", 30000)' ) ;
3635+ expect ( capturedPage . eval ) . toHaveBeenCalledWith ( 'await waitForSelector("body", 30000)' ) ;
36143636 expect ( logger . stderr ) . toEqual ( jasmine . arrayContaining ( [
36153637 '[percy:core:discovery] Wait for selector: body' ,
36163638 '[percy:core:discovery] Wait for 100ms timeout'
0 commit comments