业力报道总是显示100%

时间:2013-08-12 09:30:41

标签: angularjs code-coverage karma-runner

我的karma.conf.js文件如下所示:

// Karma configuration
// Generated on Tue Jun 11 2013 14:14:12 GMT+0100 (GMT Daylight Time)


// base path, that will be used to resolve files and exclude
basePath = '';


// list of files / patterns to load in the browser
files = [
    JASMINE,
    JASMINE_ADAPTER,
    '../Scripts/angular/angular.js',
    '../Scripts/angular/restangular/underscore-min.js',
    '../Scripts/angular/restangular/restangular-min.js',
    '../Scripts/angular/angular-*.js',
    '../Scripts/angular/angular-test/angular-*.js',
    '../Scripts/angular/angular-ui/*.js',
    '../Scripts/angular/angular-strap/*.js',
    '../Scripts/angular/angular-http-auth/*.js',
    '../uifw/scripts/ui-framework-angular.js',
    '../app/app.js',
    '../app/**/*.js',
    'unit/**/*.js'
];


// list of files to exclude
exclude = [
  '../Scripts/angular/angular-test/angular-scenario.js'
];

preprocessors = {
  '**/../app/**/*.js': 'coverage'
};



coverageReporter = {
    type: 'html',
    dir: 'coverage/'
};


// test results reporter to use
// possible values: 'dots', 'progress', 'junit'
reporters = ['progress', 'coverage'];


// web server port
port = 9876;


// cli runner port
runnerPort = 9100;


// enable / disable colors in the output (reporters and logs)
colors = true;


// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel = LOG_DEBUG;


// enable / disable watching file and executing tests whenever any file changes
autoWatch = true;


// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers = ['Chrome'];


// If browser does not capture in given timeout [ms], kill it
captureTimeout = 60000;


// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun = false;

我的文件夹结构如下所示:

Root
 |__ App
 |__ Scripts
 |__ Tests
 |__ .... other folders

Karma.conf.js位于tests文件夹中。 Karma start karma.conf.jtests文件夹中运行。

我的测试运行并创建了一个coverage文件夹,但覆盖率始终显示为100%。

Coverage

我做错了什么?

编辑:

事实上,事实证明这是一个简单的答案。 preprocessors = { '**/../app/**/*.js': 'coverage' }; 不再需要以**

作为前缀

请参阅this for more details

3 个答案:

答案 0 :(得分:0)

您需要设置ANGULAR_SCENARIO_ADAPTERKarma不使用JASMINE_ADAPTER

答案 1 :(得分:0)

对我来说,似乎您的问题是您无法找到您尝试为其生成报道的任何文件。您的报告确实说是0/0行,0/0语句等等。

我有一个类似的问题是由我使用小写字母而不是大写字母引起的,似乎你可能遇到与你有一个名为“App”的文件夹相同的问题,但你在“app”中引用了它配置。通过编写**/../App/**/*.js': 'coverage'

,查看是否可以使其工作

我也不确定,但我认为你应该写../App/**/*.js': 'coverage'代替**/../App/**/*.js': 'coverage'

答案 2 :(得分:0)

使用istanbul-instrumenter-loader设置webpack让我走上正轨。 { test: /\.ts/, include: helpers.root('src', 'app'), loader: 'istanbul-instrumenter-loader', enforce: 'post' }