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

Stop cucumber Before hook clobbering mocha before. #216

Merged
merged 2 commits into from
Aug 24, 2019

Conversation

jcundill
Copy link
Contributor

Differentiate between Before as a cucumber Hook and before as the cypress mocha hook. This PR allows both to be defined and invoked appropriately.

Also fix the issues with mocha before and after hooks getting called multiple times #214 (comment). Changed the loader to wrap the required imports into the describe block for the generated testsuite.

There is a sample repo to illustrate the results on hook invocation of this PR at https://github.com/jcundill/cypressHooks.git

Screenshot 2019-08-23 at 14 34 14

Note: For global step definitions all mocha hooks are at the Global scope - so beforeEach applies to all scenarios, etc. As the support pages are included into the cypress runner outside of any test scopes.

For local step definitions, mocha hooks scope appropriately. Those in common are applied to all features individually - before and after is called at the feature level. Those in step definition and helper files scoped to a single feature are applied just to that feature. This seems OK to me.

Also there seems to be a bug in cypress itself with regard to the mocha after hook when specified at the global level. This hook is applied after the first test rather than after all of them - run the js files just_cypress and just_cypress2 included in the test repo to reproduce this outside of the cypress-cucumber-plugin

Move loader required files into describe block of test.
@lgandecki
Copy link
Collaborator

lgandecki commented Aug 23, 2019

man, you've outran me here :) Thanks for the work! I've done the same change for adding the describe block inside the template, inspired by this comment : cypress-io/cypress#3323 (comment)

I was also going to remove overwriting of the before/after, but I was also thinking about not doing Before/After .. maybe calling them something like CucumberBefore CucumberAfter, so they are not confusing. It feels a bit weird to have both before and Before globally accessible that do something very different. What do you think? The other thing would be not to put them on window at all, but make people explicitly import them from our package.

Take Before and After off global scope.
@lgandecki lgandecki merged commit 1f8bcfb into badeball:master Aug 24, 2019
lgandecki added a commit that referenced this pull request Aug 24, 2019
There was an issue with a patch release, so this manual-releases.md
change is to release a new patch version.

Reference: #216 #214
@lgandecki
Copy link
Collaborator

🎉 This PR is included in version 1.14.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@jcundill jcundill deleted the fixBeforeHooks branch August 31, 2019 20:51
@vospascal
Copy link

updated to latest version..

Given('some description', () => {
cy.log("12321")
Cypress.log({message: '123213'})
console.log('sdfsdf')
}

or

When('some description', () => {
cy.log("12321")
Cypress.log({message: '123213'})
console.log('sdfsdf')
}

nothing gets logged anywhere... any idea's ?

@lgandecki
Copy link
Collaborator

Could you please create a separate issue?

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 this pull request may close these issues.

4 participants