@@ -66,13 +66,8 @@ const registerHooks = () => {
6666    windowCoverageObjects  =  [ ] 
6767
6868    const  saveCoverageObject  =  ( win )  =>  { 
69-       // if the application code has been instrumented, then the app iframe "win.__coverage__" will be available, 
70-       // in addition, accessing win.__coverage__ can throw when testing cross-origin code, 
71-       // because we don't control the cross-origin code, we can safely return 
72-       let  applicationSourceCoverage 
73-       try  { 
74-         applicationSourceCoverage  =  win ?. __coverage__ 
75-       }  catch  { } 
69+       // if application code has been instrumented, the app iframe "window" has an object 
70+       const  applicationSourceCoverage  =  win . __coverage__ 
7671      if  ( ! applicationSourceCoverage )  { 
7772        return 
7873      } 
@@ -148,39 +143,49 @@ const registerHooks = () => {
148143      // we can only request server-side code coverage 
149144      // if we are running end-to-end tests, 
150145      // otherwise where do we send the request? 
151-       const  url  =  Cypress . _ . get ( 
146+       const  captureUrls  =  Cypress . _ . get ( 
152147        Cypress . env ( 'codeCoverage' ) , 
153148        'url' , 
154149        '/__coverage__' 
155150      ) 
156-       cy . request ( { 
157-         url, 
158-         log : false , 
159-         failOnStatusCode : false 
160-       } ) 
161-         . then ( ( r )  =>  { 
162-           return  Cypress . _ . get ( r ,  'body.coverage' ,  null ) 
151+       function  captureCoverage ( url ,  suffix  =  '' )  { 
152+         cy . request ( { 
153+           url, 
154+           log : false , 
155+           failOnStatusCode : false 
163156        } ) 
164-         . then ( ( coverage )  =>  { 
165-           if  ( ! coverage )  { 
166-             // we did not get code coverage - this is the 
167-             // original failed request 
168-             const  expectBackendCoverageOnly  =  Cypress . _ . get ( 
169-               Cypress . env ( 'codeCoverage' ) , 
170-               'expectBackendCoverageOnly' , 
171-               false 
172-             ) 
173-             if  ( expectBackendCoverageOnly )  { 
174-               throw  new  Error ( 
175-                 `Expected to collect backend code coverage from ${ url }  
157+           . then ( ( r )  =>  { 
158+             return  Cypress . _ . get ( r ,  'body.coverage' ,  null ) 
159+           } ) 
160+           . then ( ( coverage )  =>  { 
161+             if  ( ! coverage )  { 
162+               // we did not get code coverage - this is the 
163+               // original failed request 
164+               const  expectBackendCoverageOnly  =  Cypress . _ . get ( 
165+                 Cypress . env ( 'codeCoverage' ) , 
166+                 'expectBackendCoverageOnly' , 
167+                 false 
176168              ) 
177-             }  else  { 
178-               // we did not really expect to collect the backend code coverage 
179-               return 
169+               if  ( expectBackendCoverageOnly )  { 
170+                 throw  new  Error ( 
171+                   `Expected to collect backend code coverage from ${ url }  
172+                 ) 
173+               }  else  { 
174+                 // we did not really expect to collect the backend code coverage 
175+                 return 
176+               } 
180177            } 
181-           } 
182-           sendCoverage ( coverage ,  'backend' ) 
183-         } ) 
178+             sendCoverage ( coverage ,  `backend${ suffix }  ) 
179+           } ) 
180+       } 
181+ 
182+       if  ( Array . isArray ( captureUrls ) )  { 
183+         for  ( const  [ index ,  url ]  of  captureUrls . entries ( ) )  { 
184+           captureCoverage ( url ,  `_${ index }  ) 
185+         } 
186+       }  else  { 
187+         captureCoverage ( captureUrls ) 
188+       } 
184189    } 
185190  } ) 
186191
0 commit comments