How to setup Karma runner code coverage?

爱⌒轻易说出口 提交于 2019-12-18 13:59:29

问题


I am attempting to get Karma runner to generate cobertura formatted code coverage reports during a Jenkins build. I can get it to generate a coverage.xml file, but it does not actually have any coverage data. It appears (using LOG_DEBUG) that the coverage preprocessor is not running.

The relevant pieces from my karma.conf.js file are:

files = [
  JASMINE,
  JASMINE_ADAPTER,
  'app/components/angular/angular.js',
  'app/components/angular-mocks/angular-mocks.js',
  'tmp/scripts/**/*.js',
  'tmp/spec/**/*.js'
];

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

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

junitReporter = {
  outputFile: 'test-results.xml'
};

coverageReporter = {
  type: 'cobertura',
  dir: 'coverage/',
  file: 'coverage.xml'
};

(The junit report is generating fine.)


回答1:


Apparently the karma code coverage documentation was more literal than I thought. Changing my preprocessors configuration to

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

(notice the preceding **/) did the trick. I am not sure why the syntax is different for the files array and the preprocessors object ('tmp/scripts/**/*.js' vs. '**/tmp/scripts/**/*.js').



来源:https://stackoverflow.com/questions/15648775/how-to-setup-karma-runner-code-coverage

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!