使用grunt-contrib-jasmine运行单个规范

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用grunt-contrib-jasmine运行单个规范相关的知识,希望对你有一定的参考价值。

在命令行中,如何在使用grunt-contrib-jasmine时指定要运行的单个specfile?我的茉莉花部分看起来像:

jasmine: {
  myapp: {
    src: [ 'src/base.js', 'src/**/*.js' ]
  },
  options: {
    spec: [
      'spec/models/**/*.js',
      'spec/views/**/*.js'
    ]
  }
}

我只是想为spec/models/file1.js运行测试。

答案

有人用--filter命令行参数为你完成了这个,虽然它还没有被拉入master:

https://github.com/gruntjs/grunt-contrib-jasmine/pull/70

文件名

grunt jasmine --filter=foo将运行其文件名中包含foo的spec文件。

grunt jasmine --filter=/foo将在名称中包含foo *的文件夹中运行spec文件。

通配符

grunt jasmine --filter=/*-bar将运行位于文件夹* -bar中的任何内容

逗号分隔的过滤器

grunt jasmine --filter=foo,bar将运行其文件名中包含foo或bar的spec文件。

标志与空间

grunt jasmine --filter="foo bar"将运行其文件名中包含foo bar的spec文件。

grunt jasmine --filter="/foo bar"将在名称中包含foo bar *的文件夹中运行spec文件。

另一答案

Chris Wren撰写了一篇关于Advanced Grunt Tooling的博客文章,在Running individual test specs部分下,他列出了一个示例,该示例允许命名您希望从命令行运行的规范。

以上是关于使用grunt-contrib-jasmine运行单个规范的主要内容,如果未能解决你的问题,请参考以下文章