This repository was archived by the owner on Mar 10, 2020. It is now read-only.
File tree 1 file changed +11
-3
lines changed
1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -47,17 +47,25 @@ if (Cypress.env('coverage') === false) {
47
47
windowCoverageObjects = [ ]
48
48
49
49
// save reference to coverage for each app window loaded in the test
50
- cy . on ( 'window:load' , win => {
50
+ const saveCoverageRef = ( win ) => {
51
51
// if application code has been instrumented, the app iframe "window" has an object
52
52
const applicationSourceCoverage = win . __coverage__
53
53
54
- if ( applicationSourceCoverage ) {
54
+ // do not double count in case a spec has multiple visit() calls across hooks and tests
55
+ const alreadyAdded = windowCoverageObjects . map ( ( obj ) => obj . pathname ) . includes ( win . location . pathname )
56
+
57
+ if ( applicationSourceCoverage && ! alreadyAdded ) {
55
58
windowCoverageObjects . push ( {
56
59
coverage : applicationSourceCoverage ,
57
60
pathname : win . location . pathname
58
61
} )
59
62
}
60
- } )
63
+ }
64
+
65
+ // save reference if visiting a page inside a test or in a beforeEach() hook
66
+ cy . on ( 'window:load' , win => saveCoverageRef ( win ) )
67
+ // save reference if visiting a page inside a before() hook
68
+ cy . window ( ) . then ( win => saveCoverageRef ( win ) )
61
69
} )
62
70
63
71
afterEach ( ( ) => {
You can’t perform that action at this time.
0 commit comments