@@ -3094,64 +3094,46 @@ describe('Discovery', () => {
30943094 it ( 'skips validation when hostname validation is already pending' , async ( ) => {
30953095 await percy . stop ( ) ;
30963096
3097- let validationCallCount = 0 ;
3098- let validationResolvers = [ ] ;
3099-
3100- // Mock validation to hang so we can test concurrent requests
3097+ let validationAttempted = false ;
3098+ // Track if validation is attempted (it shouldn't be)
31013099 validationMock . and . callFake ( ( ) => {
3102- validationCallCount ++ ;
3103- return new Promise ( resolve => {
3104- validationResolvers . push ( resolve ) ;
3105- } ) ;
3100+ validationAttempted = true ;
3101+ return Promise . resolve ( { accessible : false } ) ;
31063102 } ) ;
31073103
31083104 percy = await Percy . start ( {
31093105 token : 'PERCY_TOKEN' ,
3110- discovery : {
3111- autoConfigureAllowedHostnames : true
3112- }
3106+ discovery : { autoConfigureAllowedHostnames : true }
31133107 } ) ;
31143108
3109+ // Set worker URL (not used since we populate pending)
31153110 percy . domainValidation . workerUrl = 'https://winter-morning-fa32.shobhit-k.workers.dev' ;
31163111
3117- // Take two snapshots with the same external domain
3118- let snapshot1Promise = percy . snapshot ( {
3119- name : 'test snapshot 1' ,
3120- url : 'http://localhost:8000' ,
3121- domSnapshot : testExternalDOM ,
3122- widths : [ 1000 ]
3123- } ) ;
3112+ // Pre-populate pending with a resolved promise for the hostname (ex.localhost:8001 from testExternalDOM)
3113+ // This ensures the mutex path (pending.has/get) is taken instead of calling validation
3114+ percy . domainValidation . pending . set ( 'ex.localhost:8001' , Promise . resolve ( true ) ) ;
31243115
3125- let snapshot2Promise = percy . snapshot ( {
3126- name : 'test snapshot 2 ' ,
3116+ await percy . snapshot ( {
3117+ name : 'test snapshot pre-populated pending ' ,
31273118 url : 'http://localhost:8000' ,
31283119 domSnapshot : testExternalDOM ,
31293120 widths : [ 1000 ]
31303121 } ) ;
31313122
3132- // Wait for validation to be called at least once (with timeout)
3133- let attempts = 0 ;
3134- // eslint-disable-next-line no-unmodified-loop-condition
3135- while ( validationCallCount === 0 && attempts < 50 ) {
3136- await new Promise ( resolve => setTimeout ( resolve , 10 ) ) ;
3137- attempts ++ ;
3138- }
3139-
3140- // Validation should only be called once (not twice for concurrent requests)
3141- expect ( validationCallCount ) . toBe ( 1 ) ;
3142-
3143- // Resolve the validation
3144- if ( validationResolvers . length > 0 ) {
3145- validationResolvers [ 0 ] ( [ 200 , { accessible : false } ] ) ;
3146- }
3147-
3148- await Promise . all ( [ snapshot1Promise , snapshot2Promise ] ) ;
31493123 await percy . idle ( ) ;
31503124
3151- // Still only one validation call even after both snapshots complete
3152- expect ( validationCallCount ) . toBe ( 1 ) ;
3125+ // Validation endpoint should not have been called because pending was pre-populated
3126+ expect ( validationAttempted ) . toBe ( false ) ;
3127+ expect ( validationMock ) . not . toHaveBeenCalled ( ) ;
3128+ // Resource should be captured because the pending promise resolved to truthy
3129+ expect ( captured [ 0 ] ) . toContain (
3130+ jasmine . objectContaining ( {
3131+ attributes : jasmine . objectContaining ( {
3132+ 'resource-url' : 'http://ex.localhost:8001/img.gif'
3133+ } )
3134+ } )
3135+ ) ;
31533136 } ) ;
3154-
31553137 it ( 'returns the same promise for concurrent validation requests to the same hostname' , async ( ) => {
31563138 await percy . stop ( ) ;
31573139
0 commit comments