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.
Consistency between runing specs separately and all together.
reproduction here: https://github.com/TheBrainFamily/cypress-cucumber-example/tree/beforeEach
as in the repro - I used macos
Can recreate from provided repo: https://github.com/TheBrainFamily/cypress-cucumber-example/tree/beforeEach

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 filescypress run seems to reset the Mocha context between test files; each file only runs its own hooksBased 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.
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 runif possible.