Skip to content
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

Fails when using @cypress/skip-test and enableExtendedCollector #162

Closed
samtsai opened this issue Aug 12, 2022 · 2 comments
Closed

Fails when using @cypress/skip-test and enableExtendedCollector #162

samtsai opened this issue Aug 12, 2022 · 2 comments

Comments

@samtsai
Copy link

samtsai commented Aug 12, 2022

Description

When using cypress-terminal-report with enableExtendedCollector is enabled and @cypress/skip-test is used. The test will fail with a CypressError if the skip check is done in a before hook (that's why enableExtendedCollector must be enabled).

The error below is triggered by:

Reproducible Example

Run the spec test until you hit the error (sometimes it runs without an error).

https://github.com/samtsai/terminal-report-and-skip-tests-bug

Hits this CypressError:

Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.

The command that returned the promise was:

> cy.wait()

The cy command you invoked inside the promise was:

> cy.wait()

Because Cypress commands are already promise-like, you don't need to wrap them or return your own promise.

Cypress will resolve your command with whatever the final Cypress command yields.

The reason this is an error instead of a warning is because Cypress internally queues commands serially whereas Promises execute as soon as they are invoked. Attempting to reconcile this would prevent Cypress from ever resolving.

Because this error occurred during a after all hook we are skipping all of the remaining tests.[Learn more](https://on.cypress.io/returning-promise-and-commands-in-another-command)
@archfz
Copy link
Owner

archfz commented Aug 12, 2022

Unfortunately this plugin cannot do much to prevent this. We already have tests supporting dynamic skipping and they are all passing ok.

The issue is with @cypress/skip-test, as they are violating the queue nature of cypress. The following change in that plugin could fix your issue. Open an issue on that project or use patch-package.

diff --git a/node_modules/@cypress/skip-test/index.js b/node_modules/@cypress/skip-test/index.js
index 03bf1c6..359f21d 100644
--- a/node_modules/@cypress/skip-test/index.js
+++ b/node_modules/@cypress/skip-test/index.js
@@ -71,8 +71,10 @@ const isOn = (name) => {
 // @ts-ignore "cy.state" is not in the "cy" type
 const getMochaContext = () => cy.state('runnable').ctx
 const skip = () => {
-  const ctx = getMochaContext()
-  return ctx.skip()
+  cy.wrap({}).then(() => {
+    const ctx = getMochaContext()
+    return ctx.skip()
+  });
 }
 
 const isPlatform = (name) => ['win32', 'darwin', 'linux'].includes(name)

@archfz archfz closed this as completed Aug 12, 2022
@samtsai
Copy link
Author

samtsai commented Aug 12, 2022

Thanks for the follow up, I'll open a ticket with that repo.

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

No branches or pull requests

2 participants