File tree Expand file tree Collapse file tree 1 file changed +18
-10
lines changed Expand file tree Collapse file tree 1 file changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -109,16 +109,24 @@ Cypress.on('window:before:load', win => {
109
109
110
110
// Ensure code coverage data do not get lost each time a new
111
111
// page is loaded during a single test execution
112
- let coverage = { } ;
113
-
114
- Cypress . on ( 'window:before:unload' , e => {
115
- coverage = Object . assign ( coverage , e . currentTarget . __coverage__ ) ;
116
- } ) ;
117
-
118
- beforeEach ( function ( ) {
119
- coverage = { } ;
112
+ let windowCoverageObjects ;
113
+
114
+ beforeEach ( ( ) => {
115
+ windowCoverageObjects = [ ] ;
116
+ // save reference to coverage for each app window loaded in the test
117
+ cy . on ( 'window:load' , ( win ) => {
118
+ // if application code has been instrumented, the app iframe "window" has an object
119
+ const applicationSourceCoverage = win . __coverage__ ;
120
+ if ( applicationSourceCoverage ) {
121
+ windowCoverageObjects . push ( applicationSourceCoverage ) ;
122
+ }
123
+ } ) ;
120
124
} ) ;
121
125
122
- afterEach ( function ( ) {
123
- cy . task ( 'combineCoverage' , coverage ) ;
126
+ afterEach ( ( ) => {
127
+ // save coverage after the test
128
+ // because now the window coverage objects have been updated
129
+ windowCoverageObjects . forEach ( ( coverage ) => {
130
+ cy . task ( 'combineCoverage' , coverage ) ;
131
+ } ) ;
124
132
} ) ;
You can’t perform that action at this time.
0 commit comments