问题
Mocha supports it.only
syntax to reduce the amount of tests to run. In our team, a developer might use it.only
temporally within a code base.
Now it happened that such an only
test was approved and deployed by accident. This led the build server to happily run only one test and to declare that build a success.
My question now becomes: Is there a way to tell mocha:
It should only allow only
on a developer's machine? Can it be make environment aware so that either all tests always run on a build machine or an only
test case would also declare the job a failure.
(I know that there are different ways to reduce the amount of tests run by mocha. E.g. within WebStorm one can run a subset of tests within a project without changing code. The scope of the question is to allow for the fact that a developer might use it.only
and they shall be free to do so. I want to detect if such a change might sneak its way into the codebase though.)
回答1:
On your CI, you should run mocha with the forbid-only flag.
--forbid-only causes test marked with only to fail the suite
Depending on your setup it may look like:
mocha --require babel-register --recursive tests/unit --forbid-only
A developer still may chose to run the test suite without the flag.
来源:https://stackoverflow.com/questions/46911882/how-to-make-it-only-environment-aware-using-mocha