简体   繁体   English

业力在同一位置覆盖文件和测试

[英]Karma coverage with files and tests in same location

I am setting up karma in an existing project. 我正在现有项目中设置业力。 I have it working and running the tests properly, but I cannot seem to get coverage working. 我可以正常运行并运行测试,但似乎无法正常运行。

I have all the necessary modules installed, but I think it has to do with how I include my files in the "preprocessors" object. 我已经安装了所有必需的模块,但是我认为这与如何将文件包含在“预处理器”对象中有关。

My project is setup with the file structure below 我的项目使用以下文件结构进行设置

App
|--js
  |-- fileToTest.js
  |-- fileToTest.Tests.js

In the karma coverage docs it says not to include tests or libraries when setting up coverage. 在业力覆盖率文档中,它说在设置覆盖率时不包括测试或库。 I guess I'm wondering how to exclude the files with ".Tests.js" at the end. 我想我想知道如何在结尾处排除“ .Tests.js”文件。

My preprocessors object looks like below. 我的预处理器对象如下所示。 Is there a way to include the files I want to generate coverage for using a glob, or will I unfortunately have to individually add those files? 有没有一种方法可以包含要使用glob生成覆盖范围的文件,或者不幸的是我是否必须单独添加这些文件?

preprocessors: {
    './App/**/*.tpl.html' : 'ng-html2js',
    './App/**/*.js': ['coverage']
}

Karma use https://github.com/isaacs/minimatch to find the files (it's mention here http://karma-runner.github.io/0.12/config/preprocessors.html ) so you can use a glob. 业力使用https://github.com/isaacs/minimatch来查找文件(此处提到了http://karma-runner.github.io/0.12/config/preprocessors.html ),因此您可以使用glob。

On our project we just add our code from various folders, it was not that bad : 在我们的项目中,我们只是从各个文件夹中添加代码,这还不错:

preprocessors: {
          // source files, that you wanna generate coverage for
          // do not include tests or libraries
          // (these files will be instrumented by Istanbul)
          'www/js/controllers/**/*.js': ['coverage'],
          'www/js/directives/**/*.js': ['coverage'],
          'www/js/filters/**/*.js': ['coverage'],
          'www/js/initializers/**/*.js': ['coverage'],
          'www/js/services/**/*.js': ['coverage'],
          'www/js/services.js': ['coverage']
    }

EDIT : 编辑:

Reffering to this https://github.com/karma-runner/karma/issues/508 参照此https://github.com/karma-runner/karma/issues/508

It seems that this syntax is working 看来此语法有效

resources/javascript/**/!(*Spec).js

Apply to you it would be 适用于你

'./App/**/!(*Tests).js': ['coverage']

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

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