-
Notifications
You must be signed in to change notification settings - Fork 112
Description
Current behavior:
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
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