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

stepDefinitions issue #750

Closed
aomaryus opened this issue Jun 29, 2022 · 13 comments
Closed

stepDefinitions issue #750

aomaryus opened this issue Jun 29, 2022 · 13 comments

Comments

@aomaryus
Copy link

Current behavior

I have a before() that has cy.login()
The login is run for every feature when only one feature is selected

Desired behavior

before() should only run for the selected feature

Test code to reproduce

https://github.com/aomaryus/stepDefintionsIssue

Versions

  • Cypress version: 10.3
  • Preprocessor version: 11.3.1
  • Node version: v12.22.7

Checklist

  • [ yes ] I've read the FAQ.
  • [ yes ] I've read Instructions for logging issues.
  • [ yes ] I'm not using cypress-cucumber-preprocessor@4.3.1 (package name has changed and it is no longer the most recent version, see #689).
@badeball
Copy link
Owner

What is the purpose of cypress/e2e/common.feature in the example?

@aomaryus
Copy link
Author

I removed it. Was there by mistake. e2e/common should only hold common code step definitions

@JomyGeo
Copy link

JomyGeo commented Jun 30, 2022

@badeball I am facing the same issue while executing a specific feature. All Hooks (Before,beforeEach) are executed as the first step which is nowhere related to the selected feature file.

@badeball
Copy link
Owner

This patch fixes it.

diff --git a/cypress-cucumber-preprocessor.config.js b/cypress-cucumber-preprocessor.config.js
index 20c548d..c00dd4e 100644
--- a/cypress-cucumber-preprocessor.config.js
+++ b/cypress-cucumber-preprocessor.config.js
@@ -1,3 +1,3 @@
 module.exports = {
-  stepDefinitions: ['[filepath]/*.ts}', 'cypress/e2e/**/*.ts']
+  stepDefinitions: ['[filepart]/!(cypress.config).ts', 'cypress/e2e/common/**/*.ts']
 };

@badeball
Copy link
Owner

badeball commented Jun 30, 2022

@JomyGeo, you've misconfigured stepDefinitions to include all steps no matter what test is selected, thus including every hook.

@aomaryus
Copy link
Author

Hi
I tried the fix above and still see the issue

λ cat cypress-cucumber-preprocessor.config.js
module.exports = {
  stepDefinitions: ['[filepart]/!(cypress.config).ts', 'cypress/e2e/common/*.ts']
};

Also I think his path:
cypress/e2e/common/*.ts
is not sufficient - as you can see, the are definitions in cypress/e2e/**
I am not sure what to do. I have a heavily nested tree structure and it appears I have to figure out correct step Definitions path. Appreciate any help
Screen Shot 2022-06-30 at 3 21 44 PM

@badeball
Copy link
Owner

Well, in management.feature you're referencing a step definition in public.ts, so what do you really want here?

@badeball
Copy link
Owner

You're also misunderstanding entirely the purpose [filepath] and [filepart] in the search pattern. They do something, IE. cypress/e2e/common/*.ts isn't the only pattern resolving to step definitions.

@aomaryus
Copy link
Author

Well, in management.feature you're referencing a step definition in public.ts, so what do you really want here?

This means that the management.feature needs a step that is already defined in parent. This is not new stuff. It is also possible to have another directory inside management that uses steps from both management and public.

We cannot have all steps define in common.

@aomaryus
Copy link
Author

You're also misunderstanding entirely the purpose [filepath] and [filepart] in the search pattern. They do something, IE. cypress/e2e/common/*.ts isn't the only pattern resolving to step definitions.

Help me understand what you mean. What else would the pattern above include from my sample project.
I doubt if these are included in cypress/e2e/common/*.ts
cypress/e2e/public/**/*.ts cypress/e2e/private/**/*.ts cypress/e2e/network/**/*.ts

I checked with colleagues and they are having the same issues and unable to upgrade.

What if you tweak my project and test it. I will share your insight with others in my org.

Lastly, I tried DEBUG=cypress:* to see if I can find an expansion for the stepDefinitions but there was none. Is there a way to see it?

Thank you.

@badeball
Copy link
Owner

badeball commented Jul 1, 2022

Lastly, I tried DEBUG=cypress:* to see if I can find an expansion for the stepDefinitions but there was none. Is there a way to see it?

There's a debug statement mentioned in "Instructions for logging issues", linked in your original post.

@badeball
Copy link
Owner

badeball commented Jul 1, 2022

This means that the management.feature needs a step that is already defined in parent. This is not new stuff. It is also possible to have another directory inside management that uses steps from both management and public.

That's fine, but if you in management.feature want to have available public's steps, then you also get public's before hooks.

@aomaryus
Copy link
Author

aomaryus commented Jul 1, 2022

Hi
I needed to recreate the issue. Other folks could not find it.
I have removed the reference to public step but the issue is still there.

Thank you.

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

3 participants