cypress – “run all” functionality ruins my tests

so here is the deal, in some of my test specs I have a “before all” that should run. The problem is that when I click the “run all” button tests that do not have this “before all” command are being affected by it as well.

It seems like the “before all” runs before all the test specs files for each test spec. How can I run it so that it will work as clicking a single test using the cypress gui.

Using CLI is not an option because at the end my tests need to be run manually each time before a new release.

Thank you.

Answer

Beforeand BeforeEach are pretty confusing in Cypress. Actually there is a great article from Cypress genius Gleb Bahmutov about the topic of before hooks when running all specs.

Yes, before hooks at the root level will run before every single spec file when you “Run All”

The solution to your problem might be to move the before hook into the “describe” suite.

So instead of

before(() => {
   'Do that before'
    })

describe('actual spec', () => {
   'Actual Test
   })

Try moving it inside

describe('actual spec', () => {
   before(() => {
   'Do that before'
   }) 
   'Actual Test'
  })