javascript - 如何防止跳过的测试被检入源代码控制
问题描述
使用 jest 测试我们的 javascript / typescript 代码,在编写和调试时包装测试是相当普遍describe.only
的it.only
。
这将使 jest 跳过文件或块中的所有其他测试,但检查源代码控制是一个简单的更改。我已经做过很多次了。
如果跳过任何测试,导致 CI 测试失败的最佳方法是什么?有短绒或开玩笑的选择吗?我一直找不到。
解决方案
自从提出这个问题以来,我已经做了一些研究,并且我能够找到 lint 规则来处理这个问题。
对于 Javascript,有一个 eslint 插件:https ://www.npmjs.com/package/eslint-plugin-no-only-tests
对于 Typescript,tslint-microsoft-contrib repo 中有一个 tslint 插件:https ://github.com/Microsoft/tslint-microsoft-contrib称为mocha-avoid-only
我已经测试了打字稿规则,它适用于开玩笑测试。要设置它运行:npm install --save-dev tslint-microsoft-contrib
然后将以下内容添加到您的 tslint 配置中。
"rules": {
"mocha-avoid-only": true
},
"rulesDirectory": [
"node_modules/tslint-microsoft-contrib"
],
推荐阅读
- postgresql - Postgresql 跨版本转储比较
- image - Webpack dev-server 不显示内联图像
- c++ - 使用 C++11 标准的哪些规则来确定 ({ ... }) 中表达式的类型
- android - 如何从 Android 活动导航到特定的颤振路线?
- django - 除了最后一个服务器名称之外的所有内容的默认 NGINX 页面
- git - Git repo推送错误
- docker - Docker 找不到可执行文件
- angular - 属性“slidesPerView”的类型不兼容
- hibernate - 验证登录操作的用户凭据时导致我的空指针异常的原因是什么
- java - Firestore 上集合组查询的替代方法