问题描述
Mocha支持it.only
语法以减少运行的测试量.在我们的团队中,开发人员可能会在代码库中临时使用it.only
.
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.
现在,偶然发生了这样的only
测试被批准和部署的情况.这导致构建服务器仅快乐地运行一个测试,并宣布构建成功.
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:
它应该只允许在开发人员的计算机上使用only
吗?可以使环境意识吗,以便所有测试始终在构建机器上运行,或者only
测试用例也将作业声明为失败.
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.
(我知道有多种方法可以减少由mocha运行的测试量.例如,在WebStorm中,可以在不更改代码的情况下在项目中运行测试的子集.问题的范围是考虑到以下事实:开发人员可以使用it.only
,他们可以自由使用.我想检测这种更改是否会潜入代码库.)
(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.)
推荐答案
在您的CI上,应该使用 forbid-only
标志.
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.
这篇关于如何使用Mocha使`it.only`成为环境感知的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!