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

Inconsistent beforeEach behavior when 'Run all specs' executed. #3323

Closed
lgandecki opened this issue Feb 5, 2019 · 9 comments
Closed

Inconsistent beforeEach behavior when 'Run all specs' executed. #3323

lgandecki opened this issue Feb 5, 2019 · 9 comments
Labels
stage: ready for work The issue is reproducible and in scope type: bug

Comments

@lgandecki
Copy link

lgandecki commented Feb 5, 2019

Current behavior:

As one of cycpress-cucumber-preprocessor plugin users found out:
badeball/cypress-cucumber-preprocessor#139

the beforeEach defined in one file runs for every test.

Having one file:

beforeEach(() => {
  cy.log("This should run only before the first one");
});

describe("abcd", () => {
  it("dfsdfs", () => {});
});

and another:

beforeEach(() => {
  cy.log("This should run only before the second one");
});

describe("abc", () => {
  it("dfsdf", () => {});
});

I would expect them to stick to their unique beforeEaches, and that's how it works when running them separately, and when running them together using cypress run. With cypress open and the "run all specs" function - they both run both beforeEaches.

Desired behavior:

Consistency between runing specs separately and all together.

Steps to reproduce: (app code and test code)

reproduction here: https://github.com/TheBrainFamily/cypress-cucumber-example/tree/beforeEach

Versions

as in the repro - I used macos

@jennifer-shehane
Copy link
Member

@jennifer-shehane jennifer-shehane added stage: ready for work The issue is reproducible and in scope type: bug labels Feb 5, 2019
@jennifer-shehane
Copy link
Member

Related to: #1586

@xeger
Copy link

xeger commented Mar 29, 2019

My team encountered this while working with vanilla Cypress (not the Cucumber plugin).

Even more surprising, the behavior of Cypress varies depending on how it is invoked!

  • cypress open behaves as this issue describes; there is no isolation between test files
  • cypress run seems to reset the Mocha context between test files; each file only runs its own hooks

Based on the type:bug status, it sounds like the intention of Cypress is to isolate different test files?

@bahmutov
Copy link
Contributor

bahmutov commented Mar 29, 2019 via email

@xeger
Copy link

xeger commented Mar 29, 2019

The "leaky" behavior (no isolation) only happens when I click "run all tests." If I click an individual test file and later click another, isolation is maintained.

Seems to me that "run all tests" should behave more like cypress run if possible.

@technomage
Copy link

If the non-cucumber case encloses them in describe blocks do you see this behavior? In mocha use describe blocks for scope. I will test out locally.

@technomage
Copy link

Yep. If the beforeEach are within a describe block they are isolated. The cucumber template should place a describe block around the entire file content to isolate.

@jennifer-shehane jennifer-shehane changed the title Incosistent beforeEach behavior between Inconsistent beforeEach behavior between Apr 24, 2019
@jennifer-shehane jennifer-shehane changed the title Inconsistent beforeEach behavior between Inconsistent beforeEach behavior when 'Run all specs' executed. Jul 6, 2020
@napervomay
Copy link

Still reproducible on versions 7.2.0, 7.4.0 and 8.4.1.
No Cucumber, just Cypress with Mocha.

Same steps to reproduce:

  • open GUI
  • click 'Run * integration specs'

@emilyrohrbough
Copy link
Member

Run All specs functionality was removed in Cypress 10.0.0. See #21628

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: ready for work The issue is reproducible and in scope type: bug
Projects
None yet
Development

No branches or pull requests

7 participants