简体   繁体   English

是否可以通过 JSCS/JSHint 限制 fit/fdescribe 函数?

[英]Is it possible to restrict fit/fdescribe functions by JSCS/JSHint?

I am working in some development team.我在一些开发团队工作。 We have unit tests in our programm.我们的程序中有单元测试。 There are many tests in it.里面有很多测试。 Each test covers one module.每个测试涵盖一个模块。 In common, one developer is working only on one or some modules (but not many) per one task.通常,一名开发人员在一项任务中只处理一个或一些模块(但不是很多)。 To improve unit tests speed I use focused specs (I use Jasmine and our app is AngularJS app).为了提高单元测试速度,我使用了重点规范(我使用 Jasmine,我们的应用程序是 AngularJS 应用程序)。

The problem: sometimes I forget to remove focused specs.问题:有时我忘记删除重点规格。 I commit and PR with fit / fdescribe calls in programm.我在程序中使用fit / fdescribe调用提交和 PR。 It can cause problems for me and other developers in the future.将来可能会给我和其他开发人员带来问题。 Obvious example: developer is developing :), he made a mistake, he started tests and only focused specs worked, since he worked on another file - it is a problem - there will be mistake but he wouldn't see it.明显的例子:开发人员正在开发 :),他犯了一个错误,他开始测试并且只专注于规范工作,因为他在另一个文件上工作 - 这是一个问题 - 会有错误,但他不会看到它。

Is there any methods to automatically find focused specs in my tests and warn developer about it?是否有任何方法可以在我的测试中自动找到重点规范并警告开发人员? Our team is using CI with grunt running on it.我们的团队正在使用运行着 grunt 的 CI。 Grunt has tasks for jscs and jshint. Grunt 有 jscs 和 jshint 的任务。 Maybe it is somehow possible to create own rules to prevent this mistake?也许以某种方式可以创建自己的规则来防止这个错误?

I would setup a git hook and utilise grunt-ddescribe-iit .我会设置一个 git hook 并使用grunt-ddescribe-iit

For now, let's use grunt-githooks to setup the git hook.现在,让我们使用grunt-githooks来设置 git hook。

grunt.initConfig({
  githooks: {    
    options: {
      'pre-push': 'grunt ddescribe-iit'
    }
  },
  ddescribe-iit: {
    files: [
      'test/**/*.js',
      'app/**/*.spec.js'
    ]
  }
});  

That's a very contrived example of how I imagine it would work , I haven't utilised ddescribe-iit myself (though, like you - I should be!) nor have I used grunt-githooks.这是我想象它如何工作的一个非常人为的例子,我自己没有使用 ddescribe-iit(虽然,像你一样 - 我应该使用!),也没有使用 grunt-githooks。

Looking through how they're both put together however, my established guess is that this would be a fairly painless process to set up.然而,查看它们是如何组合在一起的,我确定的猜测是,这将是一个相当轻松的设置过程。

Like you, we are also utilising a CI system and it has always been a pain when a build passes, but it only ran a couple of chosen tests.和您一样,我们也在使用 CI 系统,当构建通过时总是很痛苦,但它只运行了几个选定的测试。 Using a git hook that screams in your face before pushing, kills the problem at the root I reckon (without introducing watchers and additional processes during the development step).使用一个在推送之前在你脸上尖叫的 git hook,我认为从根本上解决了问题(在开发步骤中不引入观察者和额外的过程)。

All at the amazing cost of development overhead of 0 .所有在0发展开销惊人的成本。


edit: this answer assumes that you are utilising grunt as a task runner.编辑:此答案假定您使用 grunt 作为任务运行器。 there are equivalents for gulp.等同大口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM