bahmutov/cypress-select-tests

Question/Feature: Skip execution of `before` blocks if no tests match grep?

CoryDanielson opened this issue · 5 comments

When running these tests via grep=foobar, none of the tests will match this grep, but the before block still runs. In my case, running the before block is actually quite time consuming, and it would be great to skip it when no tests match.

Would it be possible to prevent execution of the before block if non of the tests match the grep?

describe('Some Feature', () => {
  before(() => {
    // do time consuming things
  });

  it('test a', () => {});
  it('test b', () => {});
  it('test c', () => {});
  it('test d', () => {});
})

Maybe the proper solution here is to just use fgrep as well. 🤔

Maybe the proper solution here is to just use fgrep as well. 🤔

fgrep also does not work for this issue. I am running into the same issue. I have login functionality in the before hook but even if no tests match the grep or the file does not match the fgrep, the before hook executes.

I am moving my beforeEach setup code to a function that I just call from each it block

I am moving my beforeEach setup code to a function that I just call from each it block

Unfortunately that won't work in my case. My "before" block logs into an application and then then all the tests proceed. If I moved it into each "it" block, it would try to log in for each tests, which would add a lot of extra time to each test.

Any updates on this issue? I am facing this too, it's not skipping before() and after().