Karma观看特定文件

时间:2014-03-04 14:39:48

标签: javascript angularjs jasmine karma-runner

我有karma.conf.js这样:

module.exports = function(config){
    config.set({

    files : [
        'static_dev/js/lib/underscore-min.js',
        'static_dev/js/lib/angular.1.2.9.min.js',
        'static_dev/js/lib/angular-cookies.1.1.5.min.js',
        'static_dev/js/lib/ui-bootstrap-custom-tpls-0.10.0.js',
        'static_dev/js/lib/angular-tags-0.2.10-tpls.min.js',
        'static_dev/js/lib/angular-mocks.js',

        'static_dev/js/angular/modules/*.js',
        'static_dev/js/angular/controllers/**/*.js',
        'static_dev/js/angular/directives/**/*.js',
        'static_dev/js/angular/services/**/*.js',

        'static_dev/js/angular/**/test/*.js'
    ],

    reporters: ['progress', 'coverage'],

    autoWatch: true,

    colors: true,

    frameworks: ['jasmine'],

    browsers : ['PhantomJS'],

})}

一切正常,但是我想“自动观看”仅匹配'static_dev/js/angular/**/test/*.js'的文件,这可能吗?

2 个答案:

答案 0 :(得分:5)

您应该使用文件的完整模式语法,这样您就可以禁用观看您不想要的文件:

files : [
  //this pattern will NOT be watched
  {pattern: 'path/to/**/*.js', watched: false, included: true, served: true},

  //this one will be watched
  {pattern: 'path/to/other/**/*.js', watched: true, included: true, served: true}
],

 autowatch: true

请注意,watchedincludedserved默认值为 true

  

“如果autoWatchtrue,则会监视已将watched设置为true的所有文件进行更改。”

来自:Karma configuration - Files

答案 1 :(得分:2)

files : [
    ...
    {
        pattern: 'static_dev/js/angular/**/test/*.js',
        watched: true
    }
]

尝试这个