bahmutov / cypress-select-tests

User space solution for picking Cypress tests to run
96 stars 14 forks source link

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

Open CoryDanielson opened 4 years ago

CoryDanielson commented 4 years ago

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', () => {});
})
CoryDanielson commented 4 years ago

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

9odzilla commented 4 years ago

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.

CoryDanielson commented 4 years ago

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

9odzilla commented 4 years ago

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.

amercehic commented 3 years ago

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