Skip to content

Coverage plugin does not find coverage unless visiting a page before every test #150

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Closed
danmaftei opened this issue Mar 6, 2020 · 3 comments · Fixed by #152
Closed

Coverage plugin does not find coverage unless visiting a page before every test #150

danmaftei opened this issue Mar 6, 2020 · 3 comments · Fixed by #152
Assignees
Labels

Comments

@danmaftei
Copy link

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

@danmaftei 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
@jennifer-shehane
Copy link
Member

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.

@jennifer-shehane jennifer-shehane transferred this issue from cypress-io/cypress Mar 9, 2020
@jennifer-shehane
Copy link
Member

jennifer-shehane commented Mar 9, 2020

Essentially a duplicate of #137 but leaving open in case @bahmutov wants to close the other issue since this contains more detail.

@bahmutov
Copy link
Contributor

bahmutov commented Mar 9, 2020

🎉 This issue has been resolved in version 1.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants