question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hooks Are Not Run if Defined in Cypress/support/

See original GitHub issue

Current behavior

It’s mentioned here that Cypress/support/index.js is a good place to set reusable hooks, but if I define a Cucumber hook in this file they are never run. Mocha hooks DO run, but I need to use tags so I want to use the Cucumber hooks if possible. Is there a specific reason the Cucumber hooks aren’t being run when placed in the support directory but mocha hooks are?

Desired behavior

Cucumber hooks run when placed/imported into the Cypress/support/index.js file.

Test code to reproduce

Just use the Cypress example repo and place a Cucumber hook in Cypress/support/index.js such as

Before(() => {
cy.log('Anything?');
});

And you can see this hook is not run and nothing is logged. If you change it to the mocha hook

before(() => {
cy.log('Anything?');
});

You will see this run and log Anything?.

Versions

  • Cypress version: 4.4.1
  • Preprocessor version: 2.3.1
  • Node version: 12.2.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
AlexK777commented, Sep 15, 2020

Here is a repo you can use for reproduction. In support/index.js there is a Cucumber Before hook and a Mocha before hook. When you run the feature you can see that only the Mocha hook is being executed. I also tried removing the Mocha hook completely so only the Cucumber hook existed, but then no hooks were run.

Screen Shot 2020-09-15 at 2 54 33 PM

https://github.com/AlexK777/cypress-example-kitchensink

  1. Run nvm use then yarn.
  2. Run yarn cy:open.
  3. Run the only feature from the UI and view the output in the UI.
0reactions
badeballcommented, Apr 10, 2022

Due to personal reasons, the previous maintainers of this package are stepping down and handing the reigns over to me, a long-time contributor to the project and a user of it myself. This is a responsibility I’m very excited about. Furthermore, I’d like to thank @lgandecki ++ for all the work that they’ve done so far.

Read more about the transfer of ownership here.

The repository has however moved and all outstanding issues are being closed. This is not a reflection of the perceived importance of your reported issue. However, if after upgrading to the new version, you still find there to be an issue, feel free to open up another ticket or comment below. Please make sure to read CONTRIBUTING.md before doing so.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What are Cypress Hooks and How to use Hooks in Cypress?
It runs once after completion of all the tests specified using “it” or “specify” in the “describe” or “context” block.
Read more >
Execution order of after hooks when globally defined is not ...
js do not execute last - the after hooks defined in the spec file run last. I verified this is not a UI...
Read more >
Writing and Organizing Tests - Cypress Documentation
Cypress also provides hooks (borrowed from Mocha). These are helpful to set conditions that you want to run before a set of tests...
Read more >
Cypress E2E: Before hook not working on retries
let isError = false; beforeEach(() => { cy.once('fail', (err) => { isError = true; throw err; }); if (isError) { cy.resetAll(); // or ......
Read more >
cypress-cucumber-with-tags - NPM Package Overview - Socket
cypress /support/step_definitions when nonGlobalStepDefinitions is false ... Cucumber Before hooks run after all Mocha before and beforeEach ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found