4

我的 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位于测试文件夹内。从文件夹Karma start karma.conf.j内运行。tests

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

覆盖范围

我究竟做错了什么?

编辑:

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

有关更多详细信息,请参阅此

4

3 回答 3

1

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

于 2017-06-12T20:20:57.847 回答
0

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

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

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

于 2013-09-16T13:29:22.780 回答
0

你需要设置ANGULAR_SCENARIO_ADAPTER. Karma不使用JASMINE_ADAPTER

于 2013-08-12T20:52:27.320 回答