mocha icon indicating copy to clipboard operation
mocha copied to clipboard

🚀 Feature: Possibility to return 0 exit code when tests run successfully even with fails

Open ilgonmic opened this issue 4 years ago • 5 comments

Is your feature request related to a problem or a nice-to-have?? Please describe. A clear and concise description of what the problem is. E.g. I'm always frustrated when [...]

Sometimes it is useful to separate situations when tests run successfully, and there is no infrastructure or runtime problems, and when there are some runtime problems. Possibility to return non-zero exit code only on infrastructure or runtime problems make easier integration with different toolchain.

Describe the solution you'd like A clear and concise description of what you want to happen.

Flag, something like failOnFailingTests like in Karma (https://github.com/karma-runner/karma/blob/master/docs/config/01-configuration-file.md#failonfailingtestsuite).

  • 0 exit code when tests run successfully
  • 1 exit code when something went wrong

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Karma https://github.com/karma-runner/karma/blob/master/docs/config/01-configuration-file.md#failonfailingtestsuite

Additional context Add any other context or screenshots about the feature request here.

ilgonmic avatar Mar 24 '20 15:03 ilgonmic

Sometimes it is useful to separate situations when tests run successfully, and there is no infrastructure or runtime problems, and when there are some runtime problems.

I didn't understand it. Could you explain more detail for usecases.

outsideris avatar Apr 03 '20 12:04 outsideris

Using Mocha in some build tools (for example Gradle). After Mocha successfully run, I know test status via custom loader. Then I provide test results to "parent" build system and doesn't matter on Mocha exit code. Further results will be processed, and I don't want to fail "parent" build system. But it does matter if there is some problems with infrastructure (for example Node problem). And in this case I want to get non-zero exit code of Mocha and force to fail "parent" build system.

But for now I have to fail of "parent" build system on both cases, when tests are failed which is valid situation for "parent" build system, and infrastructure problem (syntax problem e.g.) which is invalid situation for "parent" build system.

If I ignore exit code of Mocha, there is no fail on failed tests (and it is OK) and on infrastructure problem (and it is not OK)

ilgonmic avatar Apr 03 '20 13:04 ilgonmic

Thanks. This is a duplicate of...several issues. Can you run mocha <args> || true instead? This is how I've seen people treat any result as "passing"

boneskull avatar Jun 10 '20 21:06 boneskull

@boneskull Thank you for reply. I don't need any result as "passing", I think that in topic starter I incorrectly expressed the thought. Let's imagine we have states:

  • Tests passed and run successful - 0 failed tests and 0 zero code
  • Some tests failed but run successful - some failed tests and 0 zero code
  • Run failed - some infrastructure problems (for example don't find some critical module)

I want to get zero code only if no "infrastructure" problem. If I run mocha <args> || true I get zero code even in this case.

It is similar with next property in Karma https://github.com/karma-runner/karma/blob/master/docs/config/01-configuration-file.md#failonfailingtestsuite

ilgonmic avatar Jun 15 '20 10:06 ilgonmic

Note that this is related to, but does not intersect with #3559. #3559 is about changing what the non-zero exit code is on case of non-passing tests. This one is about switching to a zero exit code even when there are non-passing tests.

JoshuaKGoldberg avatar Mar 04 '24 13:03 JoshuaKGoldberg