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

Mocha hooks do not work as expected in 1.14.0 #214

Closed
ghost opened this issue Aug 22, 2019 · 15 comments
Closed

Mocha hooks do not work as expected in 1.14.0 #214

ghost opened this issue Aug 22, 2019 · 15 comments

Comments

@ghost
Copy link

ghost commented Aug 22, 2019

After the release of 1.14.0 version global before and beforeEach hooks do not work as expected.
Global before hook is being run inside each test and beforeEach hook is being run before each test as much times as there are feature files in project.
To reproduce this issue I've created a small project.

Steps to reproduce

  • git clone project
  • npm install
  • npm run run
  • run all specs
    Tests won't have any before hook and there will be 2 beforeEach hooks in output
@lgandecki
Copy link
Collaborator

Shoot. Alright, thanks, I will take a look and either revert or fix. @visusnet would you like to take a look as well, maybe?

@lgandecki
Copy link
Collaborator

hmm, does it work properly in v1.14.0 ? Or did you went straight for 1.14.1 ?

@ghost
Copy link
Author

ghost commented Aug 22, 2019

@lgandecki I cannot run it right now because of missing step implementation in 1.4.0
However, I assume that it didn't work properly as I've experienced problems with git hooks about two hours ago.

ghost pushed a commit to SparkEquation/e2e-behaviour-testing that referenced this issue Aug 22, 2019
It turns out that problems with hooks are caused by [this issue](badeball/cypress-cucumber-preprocessor#214)
@lgandecki
Copy link
Collaborator

I verified 1.14.0 and it's the same problem.
Btw, are you sure you are talking about 1.4.0 and 1.4.1? IN your repro you used 1.14.1 which is the current version

@ghost
Copy link
Author

ghost commented Aug 22, 2019

I verified 1.14.0 and it's the same problem.
Btw, are you sure you are talking about 1.4.0 and 1.4.1? IN your repro you used 1.14.1 which is the current version

Sorry, I mistyped

@lgandecki lgandecki changed the title Hooks do not work as expected in 1.4.1 Hooks do not work as expected in 1.14.1 Aug 22, 2019
@lgandecki lgandecki changed the title Hooks do not work as expected in 1.14.1 Hooks do not work as expected in 1.14.0 Aug 22, 2019
@lgandecki
Copy link
Collaborator

Actually, I think this never worked properly and is a reflection of bug in cypress. :(
cypress-io/cypress#3323

If you run the tests separately, or through npx cypress run everything should be fine. Could you please verify that on your side in ui-testing-template-cypress ?
I will try to make it work with open nonetheless, but that info would be great to have meanwhile.j

@ghost
Copy link
Author

ghost commented Aug 22, 2019

Okay, I will look into running tests through npx and update the description.
However, before hooks really work in 1.13 and do not work when I update to 1.14

@lgandecki
Copy link
Collaborator

It's not about npx, you could do the same with ./node_modules/.bin/cypress run , :) when you use the 'run' command tests are run in isolation. But you are right, Before is broken, it runs after beforeEach, and before every test (so basically behaves like beforeEach):

Screen Shot 2019-08-22 at 6 19 18 PM

instead of :

Screen Shot 2019-08-22 at 6 17 45 PM

@ghost
Copy link
Author

ghost commented Aug 22, 2019

Sure, thanks for the explanation, I just haven't used npx.
Actually, the problem with before each hook doesn't lead to an error. However, before hook not being run in time does. Thanks a lot for your quick responses.

@jcundill
Copy link
Contributor

jcundill commented Aug 22, 2019

Seems that the cucumber 'Before' hook is clobbering the mocha 'before'. I guess this is a result of https://github.com/TheBrainFamily/cypress-cucumber-preprocessor/blob/c321a171512c31700a9e856e21507955053a6cbe/lib/loader.js#L17

I tried exporting the Before hook capitalised instead of lowercased here https://github.com/TheBrainFamily/cypress-cucumber-preprocessor/blob/c321a171512c31700a9e856e21507955053a6cbe/lib/resolveStepDefinition.js#L203

and then removing the clobbering of the mocha hook in the loader line highlighted above. This results in a more expected behaviour as cypress then still recognises the mocha before hook as something that it needs to run before the actual test starts.

Interestingly, however, pre 1.14.0 with npx cypress open and run all tests it is even more of a problem as alluded to above #214 (comment).

Screenshot 2019-08-22 at 21 45 29

@jcundill jcundill changed the title Hooks do not work as expected in 1.14.0 Mocha hooks do not work as expected in 1.14.0 Aug 22, 2019
@jcundill
Copy link
Contributor

😄 I would go with explicit require - take them off the window.
Then if folks want to use both before and Before they can alias the cucumber hooks themselves in the require if they find it confusing to have both

const { Before: cukeBefore, After: cukeAfter} = require('cypress-cucumber-preprocesser/steps');

@lgandecki
Copy link
Collaborator

alright, let's do that! Would you want to add a few words to the README.md as well to document all this?

lgandecki added a commit that referenced this issue 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
@Satya-Gorla
Copy link

@lgandecki @jcundill

Cypress events also not working with version 1.14.0 and later.

https://docs.cypress.io/api/events/catalog-of-events.html#Cypress-Events

Cypress.on('test:after:run', () => {
cy.log("test")
});
this event will be executed after the test and all afterEach and after hooks run.

And also I have noticed in 1.14.0 and above versions, cucumber JSON generation is happening after "After Hook" execution. In version 1.13.0 & 1.13.1 JSON file is getting generated as soon as feature scenario execution is completed.

@jcundill
Copy link
Contributor

@sagorla I think we should run the cucumber JSON generation after the cucumber After hooks - this is what cucumber-js does. We should actually include the run Before and After hooks into the generated JSON file - this, however, has not been done yet.

I added some logging and see "test:before:run" and "test:after:run" getting called around each test. Can you maybe put together a small repo on github illustrating the problems you are seeing and I'll take a look

@lgandecki
Copy link
Collaborator

@sagorla could you please create a separate issue, as I think this one is fixed?

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