2013-03-26 34 views
20

我試圖在Jenkins構建過程中獲得Karma runner生成cobertura格式的代碼覆蓋率報告。我可以讓它生成一個coverage.xml文件,但它實際上並沒有任何覆蓋率數據。它出現(使用LOG_DEBUG)覆蓋預處理器未運行。如何設置Karma runner代碼覆蓋率?

從我karma.conf.js文件中相關的作品是:

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' 
}; 

(JUnit的報告產生的罰款。)

回答

25

顯然,karma code coverage documentation比我想象的更文字。更改我的preprocessors配置

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

(注意前面**/)的伎倆。我不知道爲什麼files陣列和preprocessors對象('tmp/scripts/**/*.js''**/tmp/scripts/**/*.js')的語法不同。

+0

謝謝!這讓我感到困惑,我只是從karma.conf.js中的文件數組中複製粘貼。 – grant 2014-05-26 17:36:30