-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
before() from support/index.js called twice #8167
Comments
Unfortunately we have to close this issue as there is not enough information to reproduce the problem. This does not mean that your issue is not happening - it just means that we do not have a path to move forward. Please comment in this issue with a reproducible example and we will consider reopening the issue. |
I'm facing the same issue. I didn't face it earlier but when I moved my tests to a folder structure inside |
@ashutoshns It's likely that this is a visual bug - that it's only in the display and not actually making 2 requests. Please provide the test code that produces the duplicate logs so that we can track down and fix the bug. Thanks! |
I confirmed that it is indeed making two requests by adding a global counter which was set to 0 and also having it print a random number. From the look of it, I'd say the var counter = 0
before(() => {
var _counter = Cypress.env('counter');
Cypress.env('counter', ++_counter);
cy.log('global counter =' + Cypress.env('counter'));
cy.log('local counter =' + ++counter);
cy.log(Math.random());
}) |
Yeah, maybe you are requiring the index file twice somehow? We recommend questions relating to how to use Cypress be asked in our community chat. Also try searching our existing GitHub issues, reading through our documentation, or searching Stack Overflow for relevant answers. |
Found out that in supportFile, when I define a function, export it and import it in some test file, then that particular test file executes all other functions/modules inside support/index.js as well, resulting in before and after hooks called twice in total. Is that an expected behavior? Why does import execute the whole file? Any way to stop it? @jennifer-shehane |
@sagenicky Please provide a full reproducible example so we can see if the behavior is expected or not for ourselves. |
Current behavior:
before() used in support/index.js being called twice.
Desired behavior:
Test code to reproduce
support/index.js
Versions
4.11.0, MacOS, Chrome
The text was updated successfully, but these errors were encountered: