Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 45c1ff4

Browse files
author
dmaftei
committed
save coverage reference for all cy.visit() locations
1 parent 9adc673 commit 45c1ff4

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

support.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,25 @@ if (Cypress.env('coverage') === false) {
4747
windowCoverageObjects = []
4848

4949
// save reference to coverage for each app window loaded in the test
50-
cy.on('window:load', win => {
50+
const saveCoverageRef = (win) => {
5151
// if application code has been instrumented, the app iframe "window" has an object
5252
const applicationSourceCoverage = win.__coverage__
5353

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) {
5558
windowCoverageObjects.push({
5659
coverage: applicationSourceCoverage,
5760
pathname: win.location.pathname
5861
})
5962
}
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))
6169
})
6270

6371
afterEach(() => {

0 commit comments

Comments
 (0)