cypress-io / cypress-grep

Filter tests using substring
137 stars 19 forks source link

Describe block with empty name leads to bad `nameToGrep` #66

Closed RomanDavlyatshin closed 3 years ago

RomanDavlyatshin commented 3 years ago

THE ISSUE Given the following spec file

describe('Main page', () => {
  it('do a flip', () => {...})

  describe('', () => {
    it('do a roll', () => {...})
  })
})

Launch cypress run --env grep="Main page do a roll"

Expected result: cypress runs "do a roll" test, "do a flip" is pending

Actual result: both tests are pending

THE CULPRIT When determining nameToGrep here suiteStack names need to be filtered after mapping.

    const nameToGrep = suiteStack
      .map((item) => item.name)
      .filter(name => !!name) // suggested fix
      .concat(name)
      .join(' ')

otherwise, empty string yields an additional space character to the name, which is kinda unexpected (resulting in double space)

WHY?

  1. Currently, there are some workarounds involving describe block, e.g. adding two interceptors with different handlers for the same request (this is exactly how I encountered the issue)
  2. I'm creating grep string automatically, so this additional space is really annoying
bahmutov commented 3 years ago

Ughh empty names seem like something to avoid, no

Sent from my iPhone

On Aug 25, 2021, at 12:51, RomanDavlyatshin @.***> wrote:

 THE ISSUE Given the following spec file

describe('Main page', () => { it('do a flip', () => {...})

describe('', () => { it('do a roll', () => {...}) }) }) Launch cypress run --env grep="Main page do a roll"

Expected result: cypress runs "do a roll" test, "do a flip" is pending

Actual result: both tests are pending

THE CULPRIT When determining nameToGrep here suiteStack names need to be filtered after mapping.

const nameToGrep = suiteStack
  .map((item) => item.name)
  .filter(name => !!name) // suggested fix
  .concat(name)
  .join(' ')

otherwise, empty string yields an additional space character to the name, which is kinda unexpected (resulting in double space)

WHY?

Currently, there are some workarounds involving describe block, e.g. adding two interceptors with different handlers for the same request (this is exactly how I encountered the issue) I'm creating grep string automatically, so this additional space is really annoying — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

RomanDavlyatshin commented 3 years ago

Well, yeah, but as I've mentioned, there is a situation when one would like to add two different handlers for the same request in the same spec.

describe('Main page', () => {
  // using describe blocks to isolate interceptors

  describe('', () => {
    it('case 1', () => {
      cy.intercept('POST', '/users/login', (req) => {
        req.continue((res) => {
          expect(res.statusCode).to.equal(200)
        })
      })
      cy.get('button[type="submit"]').click()
    })
  })

  describe('', () => {
    it('case 2', () => {
      cy.intercept('POST', '/users/login', (req) => {
        req.continue((res) => {
          expect(res.statusCode).to.equal(422)
        })
      })
      cy.get('button[type="submit"]').click()
    })
  })
})

Cypress does not support overriding interceptor handlers. So, currently, the only way to achieve that is to wrap it in the additional describe block. Giving it a name seems somewhat pointless to me. If I'm doing it wrong, correct me, please.

bahmutov commented 3 years ago

I would definitely give those blocks names

Sent from my iPhone

On Aug 25, 2021, at 13:12, RomanDavlyatshin @.***> wrote:

 Well, yeah, but as I've mentioned, there is a situation when one would like to add two different handlers for the same request in the same spec.

describe('Main page', () => { // using describe blocks to isolate interceptors

describe('', () => { it('case 1', () => { cy.intercept('POST', '/users/login', (req) => { req.continue((res) => { expect(res.statusCode).to.equal(200) }) }) cy.get('button[type="submit"]').click() }) })

describe('', () => { it('case 2', () => { cy.intercept('POST', '/users/login', (req) => { req.continue((res) => { expect(res.statusCode).to.equal(422) }) }) cy.get('button[type="submit"]').click() }) }) }) Cypress does not support overriding interceptor handlers. So, currently, the only way to achieve that is to wrap it in the additional describe block. Giving it a name seems somewhat pointless to me. If I'm doing it wrong, correct me, please.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

RomanDavlyatshin commented 3 years ago

🙆‍♂️