11/// <reference types="cypress" />
22
3+ /**
4+ * Sends collected code coverage object to the backend code
5+ * via "cy.task".
6+ */
7+ const sendCoverage = coverage => {
8+ cy . log ( 'Saving code coverage' )
9+ // stringify coverage object for speed
10+ cy . task ( 'combineCoverage' , JSON . stringify ( coverage ) , {
11+ log : false
12+ } )
13+ }
14+
315// to disable code coverage commands and save time
416// pass environment variable coverage=false
517// cypress run --env coverage=false
@@ -23,7 +35,7 @@ if (Cypress.env('coverage') === false) {
2335 const applicationSourceCoverage = win . __coverage__
2436
2537 if ( applicationSourceCoverage ) {
26- cy . task ( 'combineCoverage' , JSON . stringify ( applicationSourceCoverage ) )
38+ sendCoverage ( applicationSourceCoverage )
2739 }
2840 } )
2941 } )
@@ -54,7 +66,7 @@ if (Cypress.env('coverage') === false) {
5466 // original failed request
5567 return
5668 }
57- cy . task ( 'combineCoverage' , JSON . stringify ( coverage ) )
69+ sendCoverage ( coverage )
5870 } )
5971 }
6072
@@ -75,7 +87,7 @@ if (Cypress.env('coverage') === false) {
7587 ( fileCoverage , filename ) =>
7688 filename . startsWith ( specFolder ) || filename . startsWith ( supportFolder )
7789 )
78- cy . task ( 'combineCoverage' , JSON . stringify ( coverage ) )
90+ sendCoverage ( coverage )
7991 }
8092
8193 // when all tests finish, lets generate the coverage report
0 commit comments