Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--forbid-only doesn't recognize it.only when before crashes #3840

Closed
medikoo opened this issue Mar 19, 2019 · 10 comments
Closed

--forbid-only doesn't recognize it.only when before crashes #3840

medikoo opened this issue Mar 19, 2019 · 10 comments
Labels
status: accepting prs Mocha can use your help with this one! type: bug a defect, confirmed by a maintainer

Comments

@medikoo
Copy link

medikoo commented Mar 19, 2019

Not sure if it's a feature or a bug, but --forbid-only crashes only in case of approaching describe.only but not it.only.

It caught me by a surprise.

Is it supposed to work that way? I assume it should crash same way it crashes for describe.only

@boneskull
Copy link
Contributor

boneskull commented Mar 19, 2019

@medikoo It should be working (at least in master) as I can reproduce the failure
by running:

$ bin/mocha test/integration/fixtures/options/forbid-only/only.fixture.js --forbid-only
  forbid only - test marked with only
    1) test2


  0 passing (5ms)
  1 failing

  1) forbid only - test marked with only
       test2:
     Error: `.only` forbidden
      at Runner.runTest (lib/runner.js:515:8)
      at /Users/boneskull/projects/mochajs/mocha/lib/runner.js:647:12
      at next (lib/runner.js:441:14)
      at /Users/boneskull/projects/mochajs/mocha/lib/runner.js:451:7
      at next (lib/runner.js:362:14)
      at Immediate._onImmediate (lib/runner.js:419:5)

The contents of that file:

'use strict';

describe('forbid only - test marked with only', function() {
  it('test1', function() {});
  it.only('test2', function() {});
  it('test3', function() {});
});

@boneskull boneskull added the status: waiting for author waiting on response from OP - more information needed label Mar 19, 2019
@medikoo medikoo changed the title Make --forbid-only effective for it.only --forbid-only doesn't work if before crashes Mar 20, 2019
@medikoo medikoo changed the title --forbid-only doesn't work if before crashes --forbid-only doesn't work if before crashes Mar 20, 2019
@medikoo
Copy link
Author

medikoo commented Mar 20, 2019

@boneskull I looked closer into it, and narrowed it down.

The issue is, that it becomes ignored if before, crashes, e.g. following is a nice minimal test case that exposes it:

describe('something', () => {
  before(function() {
    this.skip();
  });
  it.only('only test', () => {});
});

describe('something else', () => {
  it('other test', () => {
    throw new Error('Fail');
  });
});

Error: `.only` forbidden is reported, only if this.skip() is commented out, otherwise we have a successful pass.

To me it already looks as a design issue, fact that those errors are reported at test runtime, and not at test definition phase (when mocha gathers all describe and it declarations).

Technically I would expect this error to be thrown before any test being run.

@medikoo medikoo changed the title --forbid-only doesn't work if before crashes --forbid-only doesn't recognize it.only when before crashes Mar 20, 2019
@boneskull
Copy link
Contributor

I haven't independently confirmed this but seems plausible enough

@boneskull boneskull added type: bug a defect, confirmed by a maintainer status: accepting prs Mocha can use your help with this one! and removed status: waiting for author waiting on response from OP - more information needed unconfirmed-bug labels Mar 20, 2019
@boneskull
Copy link
Contributor

IIRC @outsideris changed it so describe.skip would be detected at this point, but it sounds like consolidating those checks at suite definition time is what we need to do.

@outsideris
Copy link
Contributor

I confirmed this bug.

@rpgeeganage
Copy link

@boneskull ,
I like to help on fixing the bug and contribute.

@rpgeeganage
Copy link

@outsideris,
Shall I start working on this?

@rpgeeganage
Copy link

I have started looking into the bug 😄 😄

@outsideris
Copy link
Contributor

@rpgeeganage Good. :)

@plroebuck
Copy link
Contributor

describe('something', () => {
  before(function() {
    this.skip();
  });
  it.only('only test', () => {});
});

Error: `.only` forbidden is reported, only if this.skip() is commented out, otherwise we have a successful pass.

To me it already looks as a design issue, fact that those errors are reported at test runtime, and not at test definition phase (when mocha gathers all describe and it declarations).

Technically I would expect this error to be thrown before any test being run.

Unsure there is a specified priority order in which tests are filtered out...
Relevant comment from #3630...

rpgeeganage added a commit to rpgeeganage/mocha that referenced this issue Jun 10, 2019
craigtaub pushed a commit that referenced this issue May 21, 2020
…; closes #3840

* add fixtures that result in it.only combined with --forbid-only bug

* adapt forbidonly test cases to cover it.only bug

* check if forbid only option is set prior to marking a test only and throw error

* change name of only test back to previous

* use custom assertion for expecting error in forbidOnly tests

* remove empty line

* use createUnsupportedError instead of throw new Error

* use createUnsupportedError instead of throw new Error

* remove check if suite hasOnly and forbidOnly option is set as this is done before runtime

* implement markOnly instance method in suite class

* add unit test for suites markOnly method

* throw exception if --forbid-only option is set even if suite is not selected by grep

* adapt forbidOnly integration tests to check for failure if only suite is not selected by grep

* fix jsdocs of suite markonly

* Revert "fix jsdocs of suite markonly"

This reverts commit cffc71a.

* Revert "adapt forbidOnly integration tests to check for failure if only suite is not selected by grep"

This reverts commit 336425a.

* Revert "throw exception if --forbid-only option is set even if suite is not selected by grep"

This reverts commit f871782.

* Revert "add unit test for suites markOnly method"

This reverts commit c2c8dc8.

* Revert "implement markOnly instance method in suite class"

This reverts commit 4b37e3c.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Mocha can use your help with this one! type: bug a defect, confirmed by a maintainer
Projects
None yet
5 participants