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

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

Closed
ilgonmic opened this issue Mar 24, 2020 · 6 comments · Fixed by #4771
Closed
Labels
area: node.js command-line-or-Node.js-specific status: accepting prs Mocha can use your help with this one! type: feature enhancement proposal

Comments

@ilgonmic
Copy link
Contributor

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 ilgonmic added the type: feature enhancement proposal label Mar 24, 2020
ilgonmic added a commit to JetBrains/kotlin that referenced this issue Mar 24, 2020
Because mocha don't make difference between infrastructure and runtime problems and failing tests
This reverts commit e6d39ce
mochajs/mocha#4216
yalishevant pushed a commit to JetBrains/kotlin that referenced this issue Mar 26, 2020
Because mocha don't make difference between infrastructure and runtime problems and failing tests
This reverts commit e6d39ce
mochajs/mocha#4216
@outsideris
Copy link
Contributor

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.

@ilgonmic
Copy link
Contributor Author

ilgonmic commented Apr 3, 2020

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)

@boneskull
Copy link
Contributor

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 boneskull added the status: waiting for author waiting on response from OP - more information needed label Jun 10, 2020
@ilgonmic
Copy link
Contributor Author

ilgonmic commented Jun 15, 2020

@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

@JoshuaKGoldberg JoshuaKGoldberg removed the status: waiting for author waiting on response from OP - more information needed label Dec 27, 2023
@JoshuaKGoldberg JoshuaKGoldberg changed the title Possibility to return 0 exit code when tests run successfully even with fails 🚀 Feature: Possibility to return 0 exit code when tests run successfully even with fails Dec 27, 2023
@JoshuaKGoldberg JoshuaKGoldberg added status: accepting prs Mocha can use your help with this one! area: node.js command-line-or-Node.js-specific and removed status: accepting prs Mocha can use your help with this one! labels Feb 6, 2024
@JoshuaKGoldberg
Copy link
Member

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
Copy link
Member

Published in mocha@10.7.0. 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: node.js command-line-or-Node.js-specific status: accepting prs Mocha can use your help with this one! type: feature enhancement proposal
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants