cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.53k stars 3.2k forks source link

Nested .only is still ignored #28009

Closed BloodyRain2k closed 1 year ago

BloodyRain2k commented 1 year ago

Current behavior

According to #3818 the test code below shouldn't be an issue, but it still is.

Only the "outer .only" is ran, the other is ignored. Even when I'm trying to "help" Cypress by marking the "nested .only"'s describe with .only too.

Was the referenced issue only about the fact that back then Cypress was limited to running just the first .only it encountered? Because that at least is working fine, multiple .only on the same "level" are ran as expected, but it doesn't seem to check "deeper levels" after that.

Desired behavior

The behavior I was expecting was that it would simply run all tests or test sets that are marked with .only, regardless of nesting.

Test code to reproduce

describe("main test", () => {
  describe("nested test", () => {
    it.only("nested .only", () => {
      // this should run too, but doesn't
      cy.log(Cypress.currentTest.title);
    });
  });

  it.only("outer .only", () => {
    cy.log(Cypress.currentTest.title);
  });
});

Cypress Version

12.17.3

Node version

14.21.1

Operating System

Win 10 - 19045.3448

Debug Logs

No response

Other

No response

Crustum7 commented 1 year ago

Was the referenced issue only about the fact that back then Cypress was limited to running just the first .only it encountered?

That is correct. The newer versions of mocha prioritizes test case over test suite but I can't find any references in their documentation to nested tests like you have (https://mochajs.org/#exclusive-tests).

I think the intended use for the .only-feature is to have all your tests on the same nest level. Why don't you wrap the "outer .only" in its own describe?

BloodyRain2k commented 1 year ago

I think the intended use for the .only-feature is to have all your tests on the same nest level. Why don't you wrap the "outer .only" in its own describe?

That's what I was hoping to avoid as most tests in that suite were stand-alone tests, except for 1 or 2 that were a small set. But I guess since I don't want to find out where to fix the code that prevents nesting, I'll just have to group the stand-alones into their own suite and the small sets come after.

So I guess I can close this "issue" then, since it's more of a QoL than an actual bug. Or is there a tag for that and I'll just leave it open?