Cypress: Inconsistent beforeEach behavior when 'Run all specs' executed.

Created on 5 Feb 2019  ·  7Comments  ·  Source: cypress-io/cypress

Current behavior:

As one of cycpress-cucumber-preprocessor plugin users found out:
https://github.com/TheBrainFamily/cypress-cucumber-preprocessor/issues/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

3️⃣ ready for work bug

Most helpful comment

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.

All 7 comments

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?

In GUI mode do you run by clicking on each spec file or by clicking the button “run all specs”?

Sent from my iPhone

On Mar 29, 2019, at 18:16, Tony Spataro notifications@github.com wrote:

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?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

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.

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.

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.

Was this page helpful?
0 / 5 - 0 ratings