You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a test spec does a single cy.visit() in a before() hook, Cypress does not find window.__coverage__, and no coverage is collected.
Coverage is collected only if you do cy.visit() before every test (e.g., in beforeEach(), or at the start of every it()/specify()). This is not a performant solution.
Desired behavior:
Collect coverage for specs that do a single cy.visit() before all tests run.
Since the coverage plugin saves a reference to window.__coverage__ inside a beforeEach() hook, this can be easily done by saving this reference using cy.window().then(win => ...) in addition to relying on the cy.on('window:load', win => ...) hook. The former handles the use case where we cy.visit() once in before(), and the latter handles the case where a cy.visit() is done within a test.
I've forked the coverage plugin and verified the following changes fix the issue: danmaftei@45c1ff4
The text was updated successfully, but these errors were encountered:
danmaftei
changed the title
Coverage plugin does not find window.__coverage__ unless cy.visit()-ing before every test
Coverage plugin does not find coverage unless visiting a page before every test
Mar 6, 2020
This repo is only for issues relating to the Cypress product itself. If you want to open an issue on our code-coverage plugin, you should open it here. This issue will be moved to that repo.
Current behavior:
If a test spec does a single
cy.visit()
in abefore()
hook, Cypress does not findwindow.__coverage__
, and no coverage is collected.Coverage is collected only if you do
cy.visit()
before every test (e.g., inbeforeEach()
, or at the start of everyit()
/specify()
). This is not a performant solution.Desired behavior:
Collect coverage for specs that do a single
cy.visit()
before all tests run.Since the coverage plugin saves a reference to
window.__coverage__
inside abeforeEach()
hook, this can be easily done by saving this reference usingcy.window().then(win => ...)
in addition to relying on thecy.on('window:load', win => ...)
hook. The former handles the use case where wecy.visit()
once inbefore()
, and the latter handles the case where acy.visit()
is done within a test.I've forked the coverage plugin and verified the following changes fix the issue: danmaftei@45c1ff4
Test code to reproduce
I'll fork https://github.com/cypress-io/cypress-example-realworld and make a reproducible example if the above looks suspect or is unclear.
Versions
Cypress 3.8.1
@cypress/code-coverage 1.12.1
The text was updated successfully, but these errors were encountered: