Skip to content

Saving coverage before page changes in test #69

New issue

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

By clicking “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? Sign in to your account

Closed
grantbdev opened this issue Aug 31, 2019 · 2 comments · Fixed by #70
Closed

Saving coverage before page changes in test #69

grantbdev opened this issue Aug 31, 2019 · 2 comments · Fixed by #70
Labels

Comments

@grantbdev
Copy link
Contributor

From my understanding, currently this plugin will only save coverage at the end of the test. Since coverage is stored on the window, if you have a test that navigates across more pages where window gets replaced, only the coverage from the last window will get saved even though different could could have been executed in the previous pages. I would like to collect coverage from every part of the app that was executed in the test.

As a workaround, I can manually save coverage using the combineCoverage task in my test when I think I am done with executing the current page and I expect the next interaction to cause the page to change. However, this is less than ideal because it is an implementation detail that interrupts the flow of the test. It may be possible that I would also miss some coverage with this approach on something like additional form submission logic.

I have attempted to add a binding to the Cypress window events described here: https://docs.cypress.io/api/events/catalog-of-events.html#Binding-to-Events

However that generates an error about returning a promise inside a promise, so I'm not sure if it's possible to use cy.task() or combineCoverage in particular with a Cypress event listener.

Does anyone have an idea how saving coverage before a page could be automated? If it's possible, would that be a feature that could be added to this plugin?

Thank you for the work on this plugin, I find it very useful!

@grantbdev
Copy link
Contributor Author

I've had success now by accumulating references to the coverage objects every time a window loads and then combining the coverage at the end. I plan on opening a PR with my suggested changes soon.

@bahmutov
Copy link
Contributor

🎉 This issue has been resolved in version 1.11.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

2 participants