cypress-io / code-coverage

Saves the code coverage collected during Cypress tests
MIT License
431 stars 108 forks source link

Cypress detected that you returned a promise in a test, but also invoked one or more cy commands inside of that promise #844

Open DanielSchiavini opened 5 months ago

DanielSchiavini commented 5 months ago

Logs and screenshots After installing the coverage plugin, the coverage is working great! However, I constantly get this warning after each test:

[2855:0617/211145.460808:INFO:CONSOLE(68449)] "Cypress Warning: Cypress detected that you returned a promise in a test, but also invoked one or more cy commands inside of that promise.
The test title was:
  > "after each" hook
While this works in practice, it's often indicative of an anti-pattern. You almost never need to return both a promise and also invoke cy commands.
Cy commands themselves are already promise like, and you can likely avoid the use of the separate Promise.
https://on.cypress.io/returning-promise-and-commands-in-test", source: http://localhost:4000/__cypress/runner/cypress_runner.js (68449)
[2855:0617/211145.472633:INFO:CONSOLE(68449)] "Cypress Warning: Cypress detected that you returned a promise in a test, but also invoked one or more cy commands inside of that promise.
The test title was:
  > "after all" hook: collectBackendCoverage
While this works in practice, it's often indicative of an anti-pattern. You almost never need to return both a promise and also invoke cy commands.
Cy commands themselves are already promise like, and you can likely avoid the use of the separate Promise.
https://on.cypress.io/returning-promise-and-commands-in-test", source: http://localhost:4000/__cypress/runner/cypress_runner.js (68449)
[2855:0617/211145.484349:INFO:CONSOLE(68449)] "Cypress Warning: Cypress detected that you returned a promise in a test, but also invoked one or more cy commands inside of that promise.
The test title was:
  > "after all" hook: generateReport
While this works in practice, it's often indicative of an anti-pattern. You almost never need to return both a promise and also invoke cy commands.
Cy commands themselves are already promise like, and you can likely avoid the use of the separate Promise.
https://on.cypress.io/returning-promise-and-commands-in-test", source: http://localhost:4000/__cypress/runner/cypress_runner.js (68449)

This happens both in Github actions but also locally: image

Versions

"@cypress/code-coverage": "^3.12.39"
"cypress": "13.11.0",
node: v20.14.0

Describe the bug The after hooks should not mix cypress commands and promises

Link to the repo Sorry, this is a closed repository. I suspect it's easy to reproduce.