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

before() from support/index.js called twice #8167

Closed
ttomaszewski opened this issue Aug 3, 2020 · 8 comments
Closed

before() from support/index.js called twice #8167

ttomaszewski opened this issue Aug 3, 2020 · 8 comments

Comments

@ttomaszewski
Copy link

ttomaszewski commented Aug 3, 2020

Current behavior:

before() used in support/index.js being called twice.

Screenshot 2020-08-03 18 44 55

Desired behavior:

Test code to reproduce

support/index.js

// Import commands.js using ES2015 syntax:
import './commands';
import faker from 'faker';

export const nameSeed = faker.random.words(3);

before('define nameSeed', () => {
  cy.log(`Name seed for this run is: ${nameSeed}`);
});

after('log out', () => {
  cy.log(nameSeed);
});

Versions

4.11.0, MacOS, Chrome

@jennifer-shehane
Copy link
Member

I cannot recreate the issue as described in Cypress 4.11.0. Likely, the test code or the structure of the actual spec file is important to recreating the issue. Please provide the test code (in the spec file) required to run with this to recreate the issue. Thanks!

Screen Shot 2020-08-05 at 11 41 45 AM

@jennifer-shehane jennifer-shehane added stage: needs information Not enough info to reproduce the issue topic: hooks ↪ labels Aug 5, 2020
@jennifer-shehane
Copy link
Member

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.

@jennifer-shehane jennifer-shehane removed the stage: needs information Not enough info to reproduce the issue label Aug 7, 2020
@ashutoshns
Copy link

ashutoshns commented Aug 11, 2020

I'm facing the same issue. I didn't face it earlier but when I moved my tests to a folder structure inside integration folder, it started running twice.

@jennifer-shehane
Copy link
Member

@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!

@ashutoshns
Copy link

ashutoshns commented Aug 11, 2020

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 index.js is being called twice for some reason.(Adding the hook and logs) I also tried to reproduce this issue on a new dummy app but the hook was called just once and was working as per expectation. I think this could be something related to my configuration and not a cypress bug. What forum can I reach for support?

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());
})

@jennifer-shehane
Copy link
Member

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.

@sagenicky
Copy link

sagenicky commented Oct 13, 2020

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

@jennifer-shehane
Copy link
Member

@sagenicky Please provide a full reproducible example so we can see if the behavior is expected or not for ourselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants